Skip to content
Advertisement

Error when trying to set column as index in pandas dataframe

I have the following code:

JavaScript

which works fine until I do (trying to set column ‘idx’ as in index for the dataframe)

JavaScript

which throws an error

JavaScript

What does this mean ?

Advertisement

Answer

The error is when you create A with

JavaScript

If you print A.columns you will get:

JavaScript

So 'idx' is not really in your column for you to set index. Now, this would work:

JavaScript

and give:

JavaScript

However, you should fix your creation of A with just:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement