1

I want to set the following multiindexes to a pandas.Series . Currently, my indexes are [none, none], how can I change them?

Letters         bins
A              (2.212, 15.753]     4
               (15.753, 29.227]    1
B              (2.212, 15.753]     1
C              (2.212, 15.753]     1
               (15.753, 29.227]    3
               (29.227, 42.701]    2
D              (2.212, 15.753]     1
               (56.174, 69.648]    1
E              (56.174, 69.648]    1
Hugo V
  • 79
  • 6
  • Welcome to Stack Overflow! Please take some time to read [How to ask good questions?](https://stackoverflow.com/help/how-to-ask). Also, please try to create a [minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) of your own attempt and show it to us. – MarianD Apr 11 '21 at 20:54
  • Please include sample(s) in text form that we can copy and paste for helping you, we don't want to type everything in... check out [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – MarianD Apr 11 '21 at 20:54

1 Answers1

3

I think you mean to change the column names of a pandas DataFrame. You can use this, see if it helps:

df.set_index(['Letters', 'bins'], inplace=True)
Shivam Roy
  • 1,961
  • 3
  • 10
  • 23
  • i.e. change the column names before doing whatever operation (`groupby`, `stack` etc.) that applies the multiindex – smci Apr 11 '21 at 20:02