我想将 DataFrame 的列和索引限制为这样的东西
ps = PorterStemmer()
df_dic = pd.read_csv('inquirerbasic_clean.csv', sep=';', index_col=0).T
print(type(df_dic)) # pandas.core.frame.DataFrame
df_dic.index = ps.stem(df_dic.index.str.lower())
df_dic.columns = ps.stem(df_dic.columns.str.lower())
我得到这个错误:
File "<ipython-input-18-0156717e5956>", line 5, in <module>
df_dic.index = ps.stem(df_dic.index.str.lower())
File "/usr/lib/python3.6/site-packages/nltk/stem/porter.py", line 632, in stem
stem = self.stem_word(word.lower(), 0, len(word) - 1)
AttributeError: 'Index' object has no attribute 'lower'
另外,如果我将索引转换为列表:
ps.stem(list(df_dic.index.str.lower()))
我收到一条等效的错误消息:
File "/usr/lib/python3.6/site-packages/nltk/stem/porter.py", line 632, in stem
stem = self.stem_word(word.lower(), 0, len(word) - 1)
AttributeError: 'list' object has no attribute 'lower'
那么,我该如何阻止它们呢?