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.

3

1 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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy