【Python 走进NLP】NLP词频统计和处理停用词,可视化

2024-09-07 06:58

本文主要是介绍【Python 走进NLP】NLP词频统计和处理停用词,可视化,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

# coding=utf-8
import requests
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
from lxml import  etree
import time
time1=time.time()
import  bs4
import nltk
from bs4 import  BeautifulSoup
from nltk.corpus import stopwords############################抓取文本数据###########################
response = requests.get('http://php.net/')
html = response.content
# print (html)
soup = BeautifulSoup(html,"html5lib")
# 这需要安装html5lib模块
text = soup.get_text(strip=True)
tokens = [t for t in text.split()]
# print (tokens)################################处理停用词(英文停止词)#################
clean_tokens = list()
sr = stopwords.words('english')
for token in tokens:if token not in sr:clean_tokens.append(token)# ###############统计词频#################################freq = nltk.FreqDist(clean_tokens)
for key,val in freq.items():print (str(key) + ':' + str(val))########################词频可视化频率分布图:######################
freq.plot(20, cumulative=False)
# 需要安装matplotlib库

这里写图片描述

"D:\Program Files\Python27\python.exe" D:/PycharmProjects/learn2017/NLP1.py
August.:1
theChangeLog.17:1
onour:4
better.01:1
ExtensionsHuman:1
recorded:5
ModeCommand:1
Character:1
31th:1
7.1.8.:1
list:15
report:5
7.0:2
7.1:3
TracingFunction:1
14th:1
development.Fast,:1
ExtensionsDatabase:1
ExtensionsXML:1
web:1
InvolvedHelpGetting:1
page)/Focus:1
Candidate:14
ProcessingVariable:1
ReferenceBasic:1
Interfaces:1
ExtensionsCredit:1
Relase:4
7.0.24:2
blog:1
source:15
StartedIntroductionA:1
Apache:1
atwindows.php.net/qa/.The:4
2.:1
team:10
7.0.23.:1
Protocols:1
helpjNext:1
7.1.9.:1
CollectionDTrace:1
pageGScroll:1
WrappersSecurityIntroductionGeneral:1
PHP.netContactOther:1
read:10
SecurityFilesystem:1
Register:1
XFormsHandling:1
moduleSession:1
ManipulationAuthentication:1
Release:11
7.0.23:2
ExtensionsFile:1
Control:1
ExtensionsDate:1
ProcessingCryptography:1
Encoding:1
12th:1
fixes:4
PHPCookiesSessionsDealing:1
Related:4
calling:1
7.2.0:15
papersMidwest:1
ThanksSocial:1
ExtensionsNon-Text:1
popular:2
found:15
ReferenceAffecting:1
PHP:48
handlingPersistent:1
2017User:1
A:5
VariablesPredefined:1
onwindows.php.net/download/.:5
media@official_phpCopyright:1
upgrading:5
System:1
Shortcuts?This:1
relative:1
Only:1
BehaviourAudio:1
GlobalsUser:1
28th:1
PHPKeeping:1
contains:1
ExceptionsPredefined:1
parametersSupported:1
users:10
Engine:1
theChangeLog.28:1
IN:5
encouraged:10
announces:10
better.03:1
PreprocessorDownloadsDocumentationGet:1
please:10
syntaxTypesVariablesConstantsExpressionsOperatorsControl:1
availability:10
2017Forum:1
everything:1
3:6
version:5
features:5
7.1.10:2
new:5
Line:1
IS:5
announced:2
PHP.net:1
CGI:1
full:5
considerationsInstalled:1
September.:2
This:8
ExplainedPredefined:1
pPrevious:1
release:10
fixed.:2
upgrade:5
GroupMy:1
general-purpose:1
Formats:1
GenerationMail:1
PREVIEW:5
ServicesSearch:1
helping:5
search:1
News:1
language:1
ExtensionsKeyboard:1
October.:1
sGoto:1
theChangeLog.14:1
RC3.:1
better.28:1
7.1.10.:1
menu:2
NOT:5
ObjectsNamespacesErrorsExceptionsGeneratorsReferences:1
changes:5
options:1
conferencesphp[world]:1
first:3
DataMagic:1
ourwiki.Thank:1
sitesMirror:1
ExtensionsSession:1
Group:1
ExtensionsText:1
Aug:4
simple:1
OutputProcess:1
pragmatic,:1
carefully,:5
tracking:5
ReleasedThe:9
incompatibilities:5
improvements:1
world.Download5.6.31·Release:1
Basic:1
release,:3
EntriesConferences:1
The:6
tutorialLanguage:1
notes.:5
©:1
ExtensionsCompression:1
usageGarbage:1
Processing:1
visit:10
RC2.:1
Jul:1
next:2
Beta:3
2:2
2017PHP:10
SupportImage:1
flexible:1
better.Older:1
AnnouncementThe:1
Card:1
files:5
7.2.0.:4
complete:5
Language:1
Database:1
These:5
Notes·Upgrading7.1.10·Release:1
20th:1
Submitted:1
PHPUpcoming:1
nNext:1
included.:3
gScroll:1
PHP::1
Time:1
version.For:5
line:1
bug:3
thedownloadpage,:5
7.1.9:2
Sep:5
bugfix:3
7.1.8:2
ServicesCommand:1
second:2
us:5
better.31:1
ServicesWindows:1
ConnectionsSafe:1
QuotesHiding:1
MIME:1
powers:1
Archive:1
scripting:1
1.:1
DO:5
page,:5
3.:2
ExtensionsOther:2
final:1
hGoto:1
theChangeLog.06:1
2001-2017:1
onwindows.php.net/qa/.The:1
July.:1
filesConnection:1
bottomg:1
binaryInstalled:1
changes,:5
file:1
SecurityDatabase:1
You:5
ClassesContext:1
StructuresFunctionsClasses:1
information:5
Several:2
releases:5
Type:1
make:5
thebug:5
-:5
search(current:1
archive.For:5
ExtensionsServer:1
1:2
also:10
authentication:1
itemkPrevious:1
PRODUCTION!For:5
ExtensionsMathematical:1
Alpha:4
EventsSpecial:1
several:3
USE:5
planned:5
development:10
CurrentFeaturesHTTP:1
test:5
Windows:10
pageg:1
downloads:10
policy:1
IT:5
theNEWSfile,:5
Specific:2
beta:2
theChangeLog.31:1
system.THIS:5
immediate:10
suited:1
Notes·Upgrading7.0.24·Release:1
topg:1
Notes·Upgrading29:1
uploadsUsing:1
PHP's:1
wiki.Thank:4
SecurityError:1
man:2
DEVELOPMENT:5
All:10
ManipulationGUI:1
remote:1
especially:1
third:2
released:3
ReportingUsing:1
theUPGRADINGfile:5
Hypertext:1
Dynamic:1
bugs:7
websites:1
itemg:1
sitesPrivacy:1
homepageg:1
sources:5
ourdownloads:5
ExtensionsWeb:1
7.0.24.:1
binaries:10
boxPHP:1

这篇关于【Python 走进NLP】NLP词频统计和处理停用词,可视化的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1144381

相关文章

python使用fastapi实现多语言国际化的操作指南

《python使用fastapi实现多语言国际化的操作指南》本文介绍了使用Python和FastAPI实现多语言国际化的操作指南,包括多语言架构技术栈、翻译管理、前端本地化、语言切换机制以及常见陷阱和... 目录多语言国际化实现指南项目多语言架构技术栈目录结构翻译工作流1. 翻译数据存储2. 翻译生成脚本

如何通过Python实现一个消息队列

《如何通过Python实现一个消息队列》这篇文章主要为大家详细介绍了如何通过Python实现一个简单的消息队列,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录如何通过 python 实现消息队列如何把 http 请求放在队列中执行1. 使用 queue.Queue 和 reque

Python如何实现PDF隐私信息检测

《Python如何实现PDF隐私信息检测》随着越来越多的个人信息以电子形式存储和传输,确保这些信息的安全至关重要,本文将介绍如何使用Python检测PDF文件中的隐私信息,需要的可以参考下... 目录项目背景技术栈代码解析功能说明运行结php果在当今,数据隐私保护变得尤为重要。随着越来越多的个人信息以电子形

使用Python快速实现链接转word文档

《使用Python快速实现链接转word文档》这篇文章主要为大家详细介绍了如何使用Python快速实现链接转word文档功能,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 演示代码展示from newspaper import Articlefrom docx import

Python Jupyter Notebook导包报错问题及解决

《PythonJupyterNotebook导包报错问题及解决》在conda环境中安装包后,JupyterNotebook导入时出现ImportError,可能是由于包版本不对应或版本太高,解决方... 目录问题解决方法重新安装Jupyter NoteBook 更改Kernel总结问题在conda上安装了

Python如何计算两个不同类型列表的相似度

《Python如何计算两个不同类型列表的相似度》在编程中,经常需要比较两个列表的相似度,尤其是当这两个列表包含不同类型的元素时,下面小编就来讲讲如何使用Python计算两个不同类型列表的相似度吧... 目录摘要引言数字类型相似度欧几里得距离曼哈顿距离字符串类型相似度Levenshtein距离Jaccard相

Python安装时常见报错以及解决方案

《Python安装时常见报错以及解决方案》:本文主要介绍在安装Python、配置环境变量、使用pip以及运行Python脚本时常见的错误及其解决方案,文中介绍的非常详细,需要的朋友可以参考下... 目录一、安装 python 时常见报错及解决方案(一)安装包下载失败(二)权限不足二、配置环境变量时常见报错及

Python中顺序结构和循环结构示例代码

《Python中顺序结构和循环结构示例代码》:本文主要介绍Python中的条件语句和循环语句,条件语句用于根据条件执行不同的代码块,循环语句用于重复执行一段代码,文章还详细说明了range函数的使... 目录一、条件语句(1)条件语句的定义(2)条件语句的语法(a)单分支 if(b)双分支 if-else(

Python itertools中accumulate函数用法及使用运用详细讲解

《Pythonitertools中accumulate函数用法及使用运用详细讲解》:本文主要介绍Python的itertools库中的accumulate函数,该函数可以计算累积和或通过指定函数... 目录1.1前言:1.2定义:1.3衍生用法:1.3Leetcode的实际运用:总结 1.1前言:本文将详

Java深度学习库DJL实现Python的NumPy方式

《Java深度学习库DJL实现Python的NumPy方式》本文介绍了DJL库的背景和基本功能,包括NDArray的创建、数学运算、数据获取和设置等,同时,还展示了如何使用NDArray进行数据预处理... 目录1 NDArray 的背景介绍1.1 架构2 JavaDJL使用2.1 安装DJL2.2 基本操