Python 2.7 ';int';运行pyldavis时python中出现不可编辑错误 我正在ipython中运行代码(运行python 2.7版)。 调用“pyLDAvis”函数以可视化我的LDA生成的主题时发现错误。 以下错误:

Python 2.7 ';int';运行pyldavis时python中出现不可编辑错误 我正在ipython中运行代码(运行python 2.7版)。 调用“pyLDAvis”函数以可视化我的LDA生成的主题时发现错误。 以下错误:,python-2.7,visualization,lda,Python 2.7,Visualization,Lda,topics_df=pd.DataFrame([dict((y,x)表示x,y在元组中)表示主题中的元组)TypeError:'int'对象不可编辑 输入数据采用表格形式,表格中有两列“投诉ID”和“投诉txt”。我正在尝试在每一个值上运行主题模型 我传递给此函数的Python版本或参数是否存在此问题? 下面是我的代码 from stop_words import get_stop_words import pandas as pd import numpy as np from nltk

topics_df=pd.DataFrame([dict((y,x)表示x,y在元组中)表示主题中的元组)TypeError:'int'对象不可编辑

  • 输入数据采用表格形式,表格中有两列“投诉ID”和“投诉txt”。我正在尝试在每一个值上运行主题模型
我传递给此函数的Python版本或参数是否存在此问题? 下面是我的代码

from stop_words import get_stop_words
import pandas as pd
import numpy as np
from nltk import bigrams
from lib.lda import lda, visualizeLDA
from nltk.tokenize import RegexpTokenizer
from gensim import corpora, models
import gensim
import pyLDAvis.gensim

#provide path name here
mypath = " "
allcomplaints = pd.read_csv(mypath)
#combining complaints for each ID
myremarks= allcomplaints.groupby(['complaint_ID'])['complaint_txt'].agg(lambda x: ''.join(x)).values 
#create English stop words list
en_stop = get_stop_words('en')

#including domain specific stop words
my_stopwords = ["xx","xxxx"]
my_stopwords= [i.decode('utf-8') for i in my_stopwords]
en_stop = en_stop +my_stopwords

texts = []
for doc in myremarks:
        raw = doc.lower()
        tokens = bigrams(i for i in tokenizer.tokenize(raw)if not i in en_stop and len(i)>1)
        mergedtokens = [i[0]+" "+i[1] for i in tokens]
        stopped_tokens = [i for i in mergedtokens if not i in en_stop]
        texts.append(stopped_tokens)
dictionary = corpora.Dictionary(texts)
print dictionary
    # convert tokenized documents into a document-term matrix
corpus = [dictionary.doc2bow(text) for text in texts]

    # generate LDA model
ldamodel = gensim.models.ldamodel.LdaModel(corpus, num_topics = 5 , id2word = dictionary, passes = 1)
print(ldamodel.print_topics(num_topics=5))

#     Visualize ldamodel
vis= pyLDAvis.gensim.prepare(ldamodel,corpus,dictionary)
pyLDAvis.display(vis)
#以下是我用于运行LDA的数据示例:

Complaint_ID| Complaint_txt
------------| --------------
4545        | cust has billing issue
4545        | for $480 
6878        | connct issue for a day ne
6878        | ed immediate resoltn

大家好,欢迎来到StackOverflow。请花些时间阅读帮助页面,特别是命名和的部分。更重要的是,请阅读。您可能还想了解。请提供一个@AllDani.com。我刚刚更新了帖子。谢谢打印“你想迭代的每件事(做一个‘for循环’”)。这些都是真的吗?其中一个可能是号码吗?@AllDani.com。请检查更新的问题,其中包含我正在尝试运行的示例数据。谢谢大家好,欢迎来到StackOverflow。请花些时间阅读帮助页面,特别是命名和的部分。更重要的是,请阅读。您可能还想了解。请提供一个@AllDani.com。我刚刚更新了帖子。谢谢打印“你想迭代的每件事(做一个‘for循环’”)。这些都是真的吗?其中一个可能是号码吗?@AllDani.com。请检查更新的问题,其中包含我正在尝试运行的示例数据。谢谢