Python 字数列表无法重命名列名

Python 字数列表无法重命名列名,python,pandas,dataframe,Python,Pandas,Dataframe,我有一段代码,读取“NAME”列,并返回每个单词出现的单词 temp_df = pd.read_excel('file location here', index=True) final_df = pd.Series(' '.join([unicode(i) for i in temp_df.NAME]).split()).value_counts() 问题是,第一列是单词的名称,它在默认情况下总是成为索引,即使我这样做 final_df.rename({0: 'word', 1: 'cou

我有一段代码,读取“NAME”列,并返回每个单词出现的单词

temp_df = pd.read_excel('file location here', index=True)

final_df = pd.Series(' '.join([unicode(i) for i in temp_df.NAME]).split()).value_counts()
问题是,第一列是单词的名称,它在默认情况下总是成为索引,即使我这样做

final_df.rename({0: 'word', 1: 'count'})

它会告诉我只存在1个元素,但我试图重命名2个元素,但原因是它将“word”列作为索引,知道如何解决这个问题吗?

输出是
系列,因此需要:

另一个解决方案:

final_df = final_df.reset_index(name='count').rename(columns={'index':'word'})
final_df = final_df.reset_index(name='count').rename(columns={'index':'word'})