error when trying to set a column as an index in pandas dataframe

The error is when you create A with

columns = [['att1', 'att2']]

If you print A.columns you will get:

            ( 'idx',)],

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


and give:

       att1 att2
a         1    2
b         1    3
c         4    6

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

columns = ['att1', 'att2']

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top