Ravi
Ravi

Reputation: 13

Keyerror even though column exists

Below is the code I used:

temp_df = pd.DataFrame(temp, columns=["Top","Column number","Row number"])
temp_df = temp_df.sort_values(by=["Top"],axis=1)

The second line is throwing the following error: error

I literally have no clue as to why it is throwing an error. Please help me out.

Upvotes: 0

Views: 1454

Answers (1)

Pierre D
Pierre D

Reputation: 26201

It's the axis=1 in your .sort_values() that's causing problems: there is no such index 'Top' (but there is a column 'Top').

In other words, change your second line to:

temp_df = temp_df.sort_values(by='Top')

Upvotes: 3

Related Questions