Home > Net >  All my columns are indexes in pandas. How to solve that and 'reset' the index?
All my columns are indexes in pandas. How to solve that and 'reset' the index?

Time:06-20

So, When i do print(mydf.columns) with my one of my dataframes, i get this result:

Index([
   'facility', '2022-01-01', '2022-02-01', '2022-03-01', '2022-04-01', 'YTD', 'state_name'
   ],
   dtype='object'
)

And because of that I can't join this dataframe with another one because i simply cannot specify which column i want to use as join parameter. To get that dataframe, i used this command:

mydf = mydf[(mydf['facility'] != "Insert New ") & (mydf['facility'] != "Total")]

How can i fix this?

CodePudding user response:

you can run set_index to set an index:

[ins] In [14]: df
Out[14]: 
   foo  bar
0    1    3
1    2    4
2    3    5

[ins] In [15]: df.set_index("foo")
Out[15]: 
     bar
foo     
1      3
2      4
3      5

  • Related