Hi Guys,
I have one DataFrame in pandas as given below.
import pandas as pd
df = pd.read_csv('my.csv')
Place |
State |
0 |
Kolkata |
WestBengal |
1 |
Delhi |
Delhi |
2 |
Bangalore |
Karnataka |
3 |
Kolkata |
WestBengal |
4 |
Delhi |
Delhi |
I am trying to drop the Place column from this DataFrame using drop() function. But it is showing me the below error.
df.drop('Place')
KeyError Traceback (most recent call last)
<ipython-input-16-5010dfe7568c> in <module>
----> 1 df.drop('Place',axis=0)
~\anaconda3\envs\myenv\lib\site-packages\pandas\core\frame.py in drop(self, labels, axis, index, columns, level, inplace, errors)
3995 level=level,
3996 inplace=inplace,
-> 3997 errors=errors,
3998 )
3999
~\anaconda3\envs\myenv\lib\site-packages\pandas\core\generic.py in drop(self, labels, axis, index, columns, level, inplace, errors)
3934 for axis, labels in axes.items():
3935 if labels is not None:
-> 3936 obj = obj._drop_axis(labels, axis, level=level, errors=errors)
3937
3938 if inplace:
~\anaconda3\envs\myenv\lib\site-packages\pandas\core\generic.py in _drop_axis(self, labels, axis, level, errors)
3968 new_axis = axis.drop(labels, level=level, errors=errors)
3969 else:
-> 3970 new_axis = axis.drop(labels, errors=errors)
3971 result = self.reindex(**{axis_name: new_axis})
3972
~\anaconda3\envs\myenv\lib\site-packages\pandas\core\indexes\base.py in drop(self, labels, errors)
5015 if mask.any():
5016 if errors != "ignore":
-> 5017 raise KeyError(f"{labels[mask]} not found in axis")
5018 indexer = indexer[~mask]
5019 return self.delete(indexer)
KeyError: "['Place'] not found in axis"
How can I solve this error?