I'm trying to perform a simple groupby operation but it's receiving an error message "level > 0 only valid with MultiIndex" and being a python newbie, I don't understand what that means or know where the error is.
In my data frame di, I have three variables disabled, wpfinwgt, and rhcalmn, whose values run from 1 to 12 (one for each calender month). I want to sum the two variables by rhcalmn. the code I have is:
di_bymonth=di.groupby(level=['rhcalmn']).sum()[['disabled','wpfinwgt']] and I get
ValueError: level > 0 only valid with MultiIndex What is wrong with it? Thanks for your help.
31 Answer
why you need level parameter. why cant you just use
> di_bymonth=di.groupby('rhcalmn').sum()[['disabled','wpfinwgt']] Add some sample data, If this is not what you are expecting
1
0 only valid with MultiIndex"">