2
我正在使用熊猫并尝试用另一个值替换值。我究竟做错了什么?使用熊猫更改列值
Source
Drive-By
Referral
Website
Radio
我的片段:
import pandas as pd
second = pd.read_csv('T:/pythonfiles/result2.csv')
second['Source'] = second['Source'].replace('Drive-By', 'Drive-by')
错误:
File "pandas/src/hashtable_class_helper.pxi", line 732, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:13161)
File "pandas/src/hashtable_class_helper.pxi", line 740, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:13115)
KeyError: 'Source'
'KeyError:'Source''表示Source不是数据文件中的有效标头名称。你确定你的列名是否正确? – Chuck
您可以在读取CSV文件('read_csv()'...)后输出'print(second.columns.tolist())' - 这将有助于理解您的列有什么问题 – MaxU
Thanks @查尔斯莫里斯。 Source前面有一个分号。 –