Search code examples
pythonpython-3.xpandasmulti-index

Which month has the highest cumulative sum in multiindex pandas


I have this MultiIndex pandas dataframe:

            chamber_temp
month day          
1     1    0.000000
      2    0.005977
      3    0.001439
      4   -0.000119
      5    0.000514
            ...
12    27   0.001799
      28   0.002346
      29  -0.001815
      30   0.001102
      31  -0.004189

What I want to get is which month has the highest cumsum(). What I am trying to do is for each month there should 1 value which will give me the cumulative sum of all the values for day in that month, that is the problem which I am trying to get help on.


Solution

  • Please Try

    df.groupby('month')['chamber_temp'].sum().idxmax()