€绘梨衣 2022-08-20 10:55 采纳率: 0%
浏览 37

中文词频分析,这是哪错了,哭了呀

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()

  • 写回答

1条回答 默认 最新

  • 「已注销」 2022-08-20 15:52
    关注

    有我在,不要哭 嗯,你把文件发给我,我看一下

    评论

报告相同问题?

问题事件

  • 创建了问题 8月20日

悬赏问题

  • ¥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 防火墙的混合模式配置