python dataframe中一直有\r\n的符号,LDA中print_topic使用循环不打印?

SUPerLeo1996 2018-05-22 11:35:33
从csv导入dataframe进行lda模型训练,最后总是会有\r\n的字符,用replace删不掉,怎么删?
neg = pd.read_csv(negfile, encoding = 'utf-8', header = None) #读入数据
stop = pd.read_csv(stoplist,encoding='utf-8',header = None, sep = 'tipdm',engine='python')
stop = [' ', ''] + list(stop[0])
neg[1] = neg[0].apply(lambda s: s.split(' '))
neg[2] = neg[1].apply(lambda x: [i for i in x if i not in stop]
neg_dict = corpora.Dictionary(neg[2])
neg_corpus = [neg_dict.doc2bow(i) for i in neg[2]]
neg_lda = models.LdaModel(neg_corpus, num_topics = 3, id2word = neg_dict)
for i in range(0,3):
neg_lda.print_topic(i)

最后的循环,为什么不打印结果,只能挨个运行才有结果

...全文
1330 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Andyjyq 2020-11-26
  • 打赏
  • 举报
回复
用 replace("\r", "") 就可以了
weixin_42653353 2020-11-02
  • 打赏
  • 举报
回复
停用词里没加 加上就没了 stopwords.txt
SUPerLeo1996 2018-05-24
  • 打赏
  • 举报
回复
怎么删除结果中的换行符啊
SUPerLeo1996 2018-05-23
  • 打赏
  • 举报
回复
有人吗,求助啊
欢乐的小猪 2018-05-23
  • 打赏
  • 举报
回复
neg_lda.print_topic(i) 改成print(neg_lda.print_topic(i))

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧