Saurabh
Saurabh

Reputation: 1662

Not able to delete 'matchId' column from pandas dataframe

I have a dataframe which looks like this

enter image description here

I tried to delete matchId but no matter what I use to delete it, for preprocessing, its outputting this error:

KeyError: "['matchId'] not found in axis"

Upvotes: 0

Views: 73

Answers (1)

Akaisteph7
Akaisteph7

Reputation: 6496

What you attempted to do (which you should have mentioned in the question) is probably failing because you assume that the matchID column is a normal column. It is actually a special, index column and so cannot be accessed in the same way other columns can be accessed.

As suggested by anky_91, because of that, you should do

df = df.reset_index(drop=True)

if you want to completely remove the indexes in your table. This will replace them with the default indexes. To just make them into another column, you can just remove the drop=True from the above statement.

Your table will always have indexes, however, so you cannot completely get rid of them.

You can, however, output it with

df.values

and this will ignore the indexes and show just the values as arrays.

Upvotes: 1

Related Questions