I am using pandas and trying to replace a value with another value. What am I doing wrong?
Source
Drive-By
Referral
Website
Radio
My snippet:
import pandas as pd
second = pd.read_csv('T:/pythonfiles/result2.csv')
second['Source'] = second['Source'].replace('Drive-By', 'Drive-by')
Error:
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'means that Source is not a valid header name within your data file. Are you sure you have the column names correct?print(second.columns.tolist())after you read the CSV file (read_csv()...) - this will help toi understand what is wrong with your columns