【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中各种常见文件的读写操作与类型转换详细指南》这篇文章主要为大家详细介绍了python中各种常见文件(txt,xls,csv,sql,二进制文件)的读写操作与类型转换,感兴趣的小伙伴可以跟... 目录1.文件txt读写标准用法1.1写入文件1.2读取文件2. 二进制文件读取3. 大文件读取3.1

使用Python实现一个优雅的异步定时器

《使用Python实现一个优雅的异步定时器》在Python中实现定时器功能是一个常见需求,尤其是在需要周期性执行任务的场景下,本文给大家介绍了基于asyncio和threading模块,可扩展的异步定... 目录需求背景代码1. 单例事件循环的实现2. 事件循环的运行与关闭3. 定时器核心逻辑4. 启动与停

基于Python实现读取嵌套压缩包下文件的方法

《基于Python实现读取嵌套压缩包下文件的方法》工作中遇到的问题,需要用Python实现嵌套压缩包下文件读取,本文给大家介绍了详细的解决方法,并有相关的代码示例供大家参考,需要的朋友可以参考下... 目录思路完整代码代码优化思路打开外层zip压缩包并遍历文件:使用with zipfile.ZipFil

Python处理函数调用超时的四种方法

《Python处理函数调用超时的四种方法》在实际开发过程中,我们可能会遇到一些场景,需要对函数的执行时间进行限制,例如,当一个函数执行时间过长时,可能会导致程序卡顿、资源占用过高,因此,在某些情况下,... 目录前言func-timeout1. 安装 func-timeout2. 基本用法自定义进程subp

Python实现word文档内容智能提取以及合成

《Python实现word文档内容智能提取以及合成》这篇文章主要为大家详细介绍了如何使用Python实现从10个左右的docx文档中抽取内容,再调整语言风格后生成新的文档,感兴趣的小伙伴可以了解一下... 目录核心思路技术路径实现步骤阶段一:准备工作阶段二:内容提取 (python 脚本)阶段三:语言风格调

Python结合PyWebView库打造跨平台桌面应用

《Python结合PyWebView库打造跨平台桌面应用》随着Web技术的发展,将HTML/CSS/JavaScript与Python结合构建桌面应用成为可能,本文将系统讲解如何使用PyWebView... 目录一、技术原理与优势分析1.1 架构原理1.2 核心优势二、开发环境搭建2.1 安装依赖2.2 验

一文详解如何在Python中从字符串中提取部分内容

《一文详解如何在Python中从字符串中提取部分内容》:本文主要介绍如何在Python中从字符串中提取部分内容的相关资料,包括使用正则表达式、Pyparsing库、AST(抽象语法树)、字符串操作... 目录前言解决方案方法一:使用正则表达式方法二:使用 Pyparsing方法三:使用 AST方法四:使用字

Java字符串处理全解析(String、StringBuilder与StringBuffer)

《Java字符串处理全解析(String、StringBuilder与StringBuffer)》:本文主要介绍Java字符串处理全解析(String、StringBuilder与StringBu... 目录Java字符串处理全解析:String、StringBuilder与StringBuffer一、St

Python列表去重的4种核心方法与实战指南详解

《Python列表去重的4种核心方法与实战指南详解》在Python开发中,处理列表数据时经常需要去除重复元素,本文将详细介绍4种最实用的列表去重方法,有需要的小伙伴可以根据自己的需要进行选择... 目录方法1:集合(set)去重法(最快速)方法2:顺序遍历法(保持顺序)方法3:副本删除法(原地修改)方法4:

Python运行中频繁出现Restart提示的解决办法

《Python运行中频繁出现Restart提示的解决办法》在编程的世界里,遇到各种奇怪的问题是家常便饭,但是,当你的Python程序在运行过程中频繁出现“Restart”提示时,这可能不仅仅是令人头疼... 目录问题描述代码示例无限循环递归调用内存泄漏解决方案1. 检查代码逻辑无限循环递归调用内存泄漏2.