从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)
最后的循环,为什么不打印结果,只能挨个运行才有结果