【python技能】词频统计
来源:互联网 发布:剑三苍云捏脸数据成女 编辑:程序博客网 时间:2024/05/16 02:18
import jiebafrom astropy.table.np_utils import joinimport osimport sysimport jieba.posseg as psegdef main(): #分词结果存储列表 word_list = [] #词频统计词典{关键词:次数} word_dict = {} current_dir = os.path.abspath('.') #自定义词典文件last文件 dict_file = os.path.join(current_dir, 'last.txt') jieba.load_userdict(dict_file) #待分词的文件 file_name = os.path.join(current_dir, 'cutTest.txt') f = open(file_name, encoding="UTF8") line = f.readline() #分词之后写入result文件 file_name2 = os.path.join(current_dir, 'result.txt') f2 = open(file_name2, 'w', encoding='utf8') while line: seg_list = jieba.cut(line, cut_all=False) #jieba.add_word("有价值信息", freq=None, tag=None) seg_list = " ".join(seg_list) word_list.extend(seg_list.split(" ")) seg_list.encode("utf8") f2.write(seg_list) f2.write("\n") line = f.readline() f2.close() f.close() for item in word_list: if item not in word_dict: word_dict[item] = 1 else: word_dict[item] += 1 for k, v in word_dict.items(): print(k, v) print("end")if __name__ == '__main__': main()
阅读全文
1 0
- 【python技能】词频统计
- python 统计词频
- python统计汉字词频
- python 统计词频
- python统计文档词频
- Python新闻联播词频统计
- python词频统计
- Python 中的词频统计
- 词频统计python
- Python进行词频统计
- python统计词频的方法
- WordsCount(词频统计)-Python语言编写!
- Python实现中文小说词频统计
- python--10行代码搞定词频统计
- python--更干净的词频统计
- python 文本单词提取和词频统计
- Python使用Hadoop进行词频统计
- Python分词并进行词频统计
- Best Cow Line POJ
- 我的服务器开发之路-安装mysql之mariadb并更改数据库路径
- CSS布局 position float
- tarjan(SCC)模板
- 15、链表中倒数第k个节点
- 【python技能】词频统计
- Django之Mode的外键自关联和引用未定义的Model
- CentOS 7 下开启Mysql-5.7.19远程访问
- 326. Power of Three
- JS运算符优先级
- 回文字符串
- 【后台】Lighttpd
- html下拉菜单样式
- 关于php 字段值MAX_FILE_SIZE 的相关问题