I have a list of value
say
df = DataFrame({'key1' : ['a', 'a', 'b', 'b', 'a'],
....: 'key2' : ['one', 'two', 'one', 'two', 'one'],
....: 'data1' : abs(np.random.randn(5)*100),
....: 'data2' : np.random.randn(5)})
So if Here's my data ,
I want to return only top 3 value of data1 and return all 4 columns
what would be the best way to do this other than a lot of if statement that I have in mind.
I was looking into nlargest , but not sure how could I do this
========================update =========================
so if run above would get this result
I would like to get return df that only have rowindex of 1,2,3 because they have highest top 3 rank of data1 ( 98,94,95 )