博客
关于我
[整理] python统计词频
阅读量:431 次
发布时间:2019-03-06

本文共 765 字,大约阅读时间需要 2 分钟。

简单的数据词频统计

import stringtext = "http requset highclient springboot requset"data = text.lower().split()words = {}for word in data:    if word not in words:        words[word] = 1    else:        words[word] = words[word] + 1result = sorted(words.items(), reverse=True)print(result)输出[('springboot', 1), ('requset', 2), ('http', 1), ('highclient', 1)]

英文书词频统计(瓦登尔湖)

import stringpath = 'D:/python3/Walden.txt'with open(path,'r',encoding= 'utf-8') as text:    words = [raw_word.strip(string.punctuation).lower() for raw_word in text.read().split()]words_index = set(words)counts_dict = {index:words.count(index) for index in words_index}for word in sorted(counts_dict,key=lambda x: counts_dict[x],reverse=True):    print('{} -- {} times'.format(word,counts_dict[word]))

转载地址:http://phcuz.baihongyu.com/

你可能感兴趣的文章
MySQL 加锁处理分析
查看>>
mysql 协议的退出命令包及解析
查看>>
mysql 参数 innodb_flush_log_at_trx_commit
查看>>
mysql 取表中分组之后最新一条数据 分组最新数据 分组取最新数据 分组数据 获取每个分类的最新数据
查看>>
MySQL 命令和内置函数
查看>>
mysql 四种存储引擎
查看>>
MySQL 在并发场景下的问题及解决思路
查看>>
MySQL 基础架构
查看>>
MySQL 基础模块的面试题总结
查看>>
MySQL 备份 Xtrabackup
查看>>
mYSQL 外键约束
查看>>
mysql 多个表关联查询查询时间长的问题
查看>>
mySQL 多个表求多个count
查看>>
mysql 多字段删除重复数据,保留最小id数据
查看>>
MySQL 多表联合查询:UNION 和 JOIN 分析
查看>>
MySQL 大数据量快速插入方法和语句优化
查看>>
mysql 如何给SQL添加索引
查看>>
mysql 字段区分大小写
查看>>
mysql 字段合并问题(group_concat)
查看>>
mysql 字段类型类型
查看>>