0

I'm trying to take the 3 highest observations for each index. For instance, I have

census=pd.Series([2000,4432,5435,43252,63463,423432,3525,54353,6363]) 
census.index=['AL','AL','AL','AL','AK','AK','AK','AK','AK']

I want to get 3 highest observation for AL and AK and get it as a different series. Thanks.

cs95
  • 379,657
  • 97
  • 704
  • 746
Sandeep
  • 67
  • 5
  • 1
    Start with `s = census.groupby(level=0).nlargest(3)` and then figure out how to fix the result yourself. – cs95 Dec 06 '18 at 03:38
  • Thanks, that answers my question, but I don't know how to mark this as the correct answer. Appreciate it. – Sandeep Dec 06 '18 at 03:58
  • At least don't accept the other answer until they fix their code. – cs95 Dec 06 '18 at 03:59

1 Answers1

0

You can do census.groupby(level=0).nlargest(3)

Thanks @coldspeed

Axel Puig
  • 1,304
  • 9
  • 19