Key error in pandas dataframe


I’m getting this error " pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: ‘column’ " and unable to plot any chart, even I’m following Codecademy instructions.

That error suggests that there’s no column named “column” within your dataframe. Consider what columns are included in your csv file and make sure you’re using a valid key.

Please could you also have a look at the following FAQ which describes the best way to set up a question for the forums (a more helpful title, a link to the lesson and a little categorisation makes it much easier for those trying to help out and anyone who was the same issue in the future).

1 Like

you could also use the .columns method to see the column names in a pandas df.

1 Like

A KeyError means the key you gave pandas isn’t valid. Before doing anything with the data frame, use print(df.columns) to see what keys are available.


I was getting a similar kind of error in one of my codes. Turns out, that particular index was missing from my data frame as I had dropped the empty dataframe rows. If this is the case, you can do df.reset_index(inplace=True) and the error should be resolved.

Apparently, you just need to omit " " around column, so it should just be

for column in columns: