综合应用,jieba,去标点,分词保存,统计,删词,输出
import jieba fp1=r'D:/python/a.txt'
outph=r'D:/python/out.txt'
f=open(fp1,'r',encoding='utf-8')
txt=f.read().strip()
f.close() words=jieba.lcut(txt)
f=open(outph,'w',encoding='utf-8')
for word in words:
f.write(word)
f.write('\n')
f.close() #第二题去标点,统计词频
bd='[’!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~]+,。!?“”《》:、. '
counts={ }
exlutes={'作者','之后'}
for i in bd:
txt=txt.replace(i,'') #字符串替换去标点符号 words=jieba.lcut(txt) #分词
for word in words:
if len(word)==1:
continue
else:
counts[word]=counts.get(word,0)+1 #所有词全统计
for word in exlutes:
del(counts[word]) #删除{a,b}
items=list(counts.items()) items.sort(key=lambda x:x[1],reverse=True)
for i in range(15):
word,count=items[i]
print("{0:>10}---{1:<5}".format(word,count))
综合应用,jieba,去标点,分词保存,统计,删词,输出的更多相关文章
- [python] 使用Jieba工具中文分词及文本聚类概念
声明:由于担心CSDN博客丢失,在博客园简单对其进行备份,以后两个地方都会写文章的~感谢CSDN和博客园提供的平台. 前面讲述了很多关于Python爬取本体Ontology.消息盒Inf ...
- [Python] 基于 jieba 的中文分词总结
目录 模块安装 开源代码 基本用法 启用Paddle 词性标注 调整词典 智能识别新词 搜索引擎模式分词 使用自定义词典 关键词提取 停用词过滤 模块安装 pip install jieba jieb ...
- python第三方库------jieba库(中文分词)
jieba“结巴”中文分词:做最好的 Python 中文分词组件 github:https://github.com/fxsjy/jieba 特点支持三种分词模式: 精确模式,试图将句子最精确地切开, ...
- Python第三方库jieba(中文分词)入门与进阶(官方文档)
jieba "结巴"中文分词:做最好的 Python 中文分词组件 github:https://github.com/fxsjy/jieba 特点 支持三种分词模式: 精确模式, ...
- Hadoop的改进实验(中文分词词频统计及英文词频统计)(4/4)
声明: 1)本文由我bitpeach原创撰写,转载时请注明出处,侵权必究. 2)本小实验工作环境为Windows系统下的百度云(联网),和Ubuntu系统的hadoop1-2-1(自己提前配好).如不 ...
- jieba 库的使用和好玩的词云
jieba库的使用: (1) jieba库是一款优秀的 Python 第三方中文分词库,jieba 支持三种分词模式:精确模式.全模式和搜索引擎模式,下面是三种模式的特点. 精确模式:试图将语句最精 ...
- spss C# 二次开发 学习笔记(六)——Spss统计结果的输出
Spss的二次开发可以很简单,实例化一个对象,然后启用服务,接着提交命令,最后停止服务. 其中重点为提交命令,针对各种统计功能需求,以及被统计分析的数据内容等,命令的内容可以很复杂,但也可以简单的为一 ...
- 819. Most Common Word 统计高频词(暂未被禁止)
[抄题]: Given a paragraph and a list of banned words, return the most frequent word that is not in the ...
- python利用jieba进行中文分词去停用词
中文分词(Chinese Word Segmentation) 指的是将一个汉字序列切分成一个一个单独的词. 分词模块jieba,它是python比较好用的分词模块.待分词的字符串可以是 unicod ...
随机推荐
- CSS工作记录
1:行内元素 设置背景图片(假设 给span) /*span 标签加背景图片 需要设置快级元素 定义高度宽度,当高度宽度很小的时候 需要设置背景图片大小*/ .filex { display: inl ...
- Django连接MySQL(二)
1.首先我们需要创建好项目 2.安装MySQL数据库 3.setting中修改database设置 DATABASES = { 'default': { 'ENGINE': 'django.db.ba ...
- 使用清华源 tensorflow 安装
1. 超级权限打开cmd.exe 2. pip install --upgrade setuptools 3. pip install -U --ignore-installed wrapt enu ...
- Android Studio: 查看SDK源代码
有时候在AS里点击某个类跳转到的仍然是这个类反编译的源代码,看起来依然不舒服,今天分享个办法: 1. 查看当前编译的SDK Version: 2. 确保当前版本的SDK源码已下载: 3. 找到andr ...
- Quartz Configuration Reference
Quartz Configuration Reference Choose a topic: Main Configuration (configuration of primary schedule ...
- 【转】Python 代码批量抓取免费高清图片!
import requests from bs4 import BeautifulSoup import random import time from fake_useragent import U ...
- osg 渲染ifc数据-测试
直接使用osg渲染ifc数据,提高渲染速度. #include "teslamanage.h" #include <QtWidgets/QApplication> #i ...
- 001——Angular环境搭建、运行项目、搭建项目
1.安装node.js 和cnpm 2.cnpm install -g @angular/cli 安装angular脚手架: 3.ng new angulardemo cd angulardemo ...
- 【DataBase】H2 DateBase与项目集成
本例介绍H2与web项目的集成 项目启动H2数据库 1.新建Maven Web项目,参考:[Maven]Eclipse 使用Maven创建Java Web项目 2.引入h2的jar包依赖 <de ...
- React错误收集
1. Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/ ...