【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实现矢量路径的压缩、解压与可视化

《使用Python实现矢量路径的压缩、解压与可视化》在图形设计和Web开发中,矢量路径数据的高效存储与传输至关重要,本文将通过一个Python示例,展示如何将复杂的矢量路径命令序列压缩为JSON格式,... 目录引言核心功能概述1. 路径命令解析2. 路径数据压缩3. 路径数据解压4. 可视化代码实现详解1

python获取网页表格的多种方法汇总

《python获取网页表格的多种方法汇总》我们在网页上看到很多的表格,如果要获取里面的数据或者转化成其他格式,就需要将表格获取下来并进行整理,在Python中,获取网页表格的方法有多种,下面就跟随小编... 目录1. 使用Pandas的read_html2. 使用BeautifulSoup和pandas3.

Python装饰器之类装饰器详解

《Python装饰器之类装饰器详解》本文将详细介绍Python中类装饰器的概念、使用方法以及应用场景,并通过一个综合详细的例子展示如何使用类装饰器,希望对大家有所帮助,如有错误或未考虑完全的地方,望不... 目录1. 引言2. 装饰器的基本概念2.1. 函数装饰器复习2.2 类装饰器的定义和使用3. 类装饰

Python 交互式可视化的利器Bokeh的使用

《Python交互式可视化的利器Bokeh的使用》Bokeh是一个专注于Web端交互式数据可视化的Python库,本文主要介绍了Python交互式可视化的利器Bokeh的使用,具有一定的参考价值,感... 目录1. Bokeh 简介1.1 为什么选择 Bokeh1.2 安装与环境配置2. Bokeh 基础2

Pandas统计每行数据中的空值的方法示例

《Pandas统计每行数据中的空值的方法示例》处理缺失数据(NaN值)是一个非常常见的问题,本文主要介绍了Pandas统计每行数据中的空值的方法示例,具有一定的参考价值,感兴趣的可以了解一下... 目录什么是空值?为什么要统计空值?准备工作创建示例数据统计每行空值数量进一步分析www.chinasem.cn处

如何使用 Python 读取 Excel 数据

《如何使用Python读取Excel数据》:本文主要介绍使用Python读取Excel数据的详细教程,通过pandas和openpyxl,你可以轻松读取Excel文件,并进行各种数据处理操... 目录使用 python 读取 Excel 数据的详细教程1. 安装必要的依赖2. 读取 Excel 文件3. 读

Python的time模块一些常用功能(各种与时间相关的函数)

《Python的time模块一些常用功能(各种与时间相关的函数)》Python的time模块提供了各种与时间相关的函数,包括获取当前时间、处理时间间隔、执行时间测量等,:本文主要介绍Python的... 目录1. 获取当前时间2. 时间格式化3. 延时执行4. 时间戳运算5. 计算代码执行时间6. 转换为指

利用Python调试串口的示例代码

《利用Python调试串口的示例代码》在嵌入式开发、物联网设备调试过程中,串口通信是最基础的调试手段本文将带你用Python+ttkbootstrap打造一款高颜值、多功能的串口调试助手,需要的可以了... 目录概述:为什么需要专业的串口调试工具项目架构设计1.1 技术栈选型1.2 关键类说明1.3 线程模

Python ZIP文件操作技巧详解

《PythonZIP文件操作技巧详解》在数据处理和系统开发中,ZIP文件操作是开发者必须掌握的核心技能,Python标准库提供的zipfile模块以简洁的API和跨平台特性,成为处理ZIP文件的首选... 目录一、ZIP文件操作基础三板斧1.1 创建压缩包1.2 解压操作1.3 文件遍历与信息获取二、进阶技

Python Transformers库(NLP处理库)案例代码讲解

《PythonTransformers库(NLP处理库)案例代码讲解》本文介绍transformers库的全面讲解,包含基础知识、高级用法、案例代码及学习路径,内容经过组织,适合不同阶段的学习者,对... 目录一、基础知识1. Transformers 库简介2. 安装与环境配置3. 快速上手示例二、核心模