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.
print(df.columns)
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.