0

I am trying to convert a Pandas multi-index to a table. I have tried stacking, unstacking, and cross-sections, but nothing seems to give quite the right output.

The multi-index table looks like this:

enter image description here

I would like to convert it to a format like this:

yearmo  cohort_string                       sum      count
2018-01 Bonds                               76418    17.0
2018-01 Bonds+Car Loan                      18538.0  17.0
2018-01 Bonds+Car Loan+Checking+Credit Card 48248.0  3.0
...

I know I could loop over the object and pull apart the pieces but there has to be a simpler way. I have spent more time on this than I care to admit, any help would be much appreciated.

Sledge
  • 1,245
  • 1
  • 23
  • 47
  • 1
    Are you looking for [`pd.DataFrame.reset_index()`](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reset_index.html)? – cmaher Mar 14 '18 at 19:35
  • That's what I was looking for. This is definitely a duplicate question. Thanks. – Sledge Mar 14 '18 at 19:49

0 Answers0