Loading csv file in python error

I have used the above article to create the classifier.
In the last, I have changed the file name as shown below.

sample = pd.read_csv(‘Sample_Submission_lxuyBuB.csv’)
sample[‘sample_submission’] = test_file[‘test.csv’]
sample[‘label’] = prediction
sample.to_csv(‘sample.csv’, header=True, index=False)

and I am getting this error

KeyError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2656 try:
-> 2657 return self._engine.get_loc(key)
2658 except KeyError:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: ‘test.csv’

I am not able to identify this thing.

Hi @tarun08,

Looks like you have a different name for the columns in your test file. Please verify that. It will solve the error.

© Copyright 2013-2019 Analytics Vidhya