【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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

东华果汁哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值