显示了列修改错误。代码在循环外完美运行,但在循环内失败

时间:2019-01-22 07:08:54

标签: python python-2.7 text counter

嗨,我正在运行代码,但在循环内失败,但在循环外失败。 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)})

0 个答案:

没有答案