def getText("红楼梦.txt"):
f = open("红楼梦.txt","r",encoding="utf-8")
text = f.read()
f.close()
return text
import jieba
def wordFreq(红楼梦.txt,text,200):
words = jieba.lcut(text.strip())
counts = {}
for word in words:
counts[word] = counts.get(word,0) + 1
items = list(counts.items())
items.sort(key = lambda x:x[1],reverse = true)
f = open(filepath[:-4]+'_词频.txt',"w")
for i in range(topn):
word, count = items[i]
f.writelines("{}\t{}\n".format(word,count))
f.ciose()
中文词频分析,这是哪错了,哭了呀
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
悬赏问题
- ¥15 华为手机相册里面的照片能够替换成自己想要的照片吗?
- ¥15 陆空双模式无人机飞控设置
- ¥15 sentaurus lithography
- ¥100 求抖音ck号 或者提ck教程
- ¥15 关于#linux#的问题:子进程1等待子进程A、B退出后退出(语言-c语言)
- ¥20 web页面如何打开Outlook 365的全球离线通讯簿功能
- ¥15 io.jsonwebtoken.security.Keys
- ¥15 急,ubuntu安装后no caching mode page found等
- ¥15 联想交换机NE2580O/NE1064TO安装SONIC
- ¥15 防火墙的混合模式配置