嗨,我正在运行代码,但在循环内失败,但在循环外失败。 m ['Count'] = m ['count']“键错误'count'” 是它在循环中失败的那一行。
for i in range(1,len(dfn)):
d=str(dfn.iloc[i]['Description'])
table = string.maketrans("","")
c=d.translate(None, string.punctuation)
c= re.sub('[0-9]+', '', c)
c=c.lower()
word_tokens = word_tokenize(c)
filtered_sentence = [w for w in word_tokens if not w in stop_words]
filtered_sentence = []
for w in word_tokens:
if w not in stop_words:
filtered_sentence.append(w)
b=Counter(filtered_sentence)
m=pd.DataFrame.from_dict(b,orient='index')
m= m.rename(columns={0: 'count'})
print m.head()
m['word']=m.index
m.set_index('word', inplace=True)
m['Count']=m['count']
del m['count']
m[m['Count']>1]=1
a=pd.DataFrame({'Count': pd.concat([a,m], axis=1).fillna(0).sum(axis=1)})