I have a DataFrame
that looks like this:
name value
date
2016-05-01 kelly 20
2016-05-05 john 12
2016-05-05 sarah 25
2016-05-05 george 3
2016-05-05 tom 40
2016-05-07 kara 24
2016-05-07 jane 90
2016-05-07 sally 39
2016-05-07 sam 28
I want to get the top 3 rows (according to value) preferably per date. I'm expecting something like this:
name value
date
2016-05-01 kelly 20
2016-05-05 john 12
2016-05-05 sarah 25
2016-05-05 tom 40
2016-05-07 jane 90
2016-05-07 sally 39
2016-05-07 sam 28
but I'm ok also with this:
name value
date
2016-05-05 tom 40
2016-05-07 jane 90
2016-05-07 sally 39
I tried df.nlargest(3, 'value')
but I get this weird result:
name value
date
2016-05-01 kelly 20
2016-05-01 kelly 20
2016-05-01 kelly 20
2016-05-05 tom 40
2016-05-05 tom 40
2016-05-05 tom 40
2016-05-05 sarah 25
2016-05-05 sarah 25
2016-05-05 sarah 25
2016-05-07 kara 24
2016-05-07 kara 24
...
2016-05-07 sally 39
2016-05-07 sally 39
2016-05-07 jane 90
2016-05-07 jane 90
2016-05-07 jane 90
I tried running it day by day:
[df.ix[day].nlargest(3, 'value') for day in df.index.unique()]
but I got the same problem (each name is duplicated 3 times)