我有数据csv
word,centroid
she,1
great,0
good,3
mother,2
father,2
After,4
before,4
.....
我只想看centroid
我的代码是:
df = pd.read_csv('data/hasil_cluster.csv',encoding = "ISO-8859-1")
print(df['centroid'])
和错误:
KeyError: 'centroid'
答案 0 :(得分:0)
在;
之后有centroid
:
print (df.columns.tolist())
['word', 'centroid;']
您可以删除列名之前和之后的所有;
:
df.columns = df.columns.str.strip(';')
或使用rename
:
df = df.rename(columns={'centroid;':'centroid'})
或重新分配列名称:
df.columns = ['word', 'centroid']