Ivan
Ivan

Reputation: 7746

Get other columns when asking for nlargest

I have a DataFrame outputDF that looks like this:

                      Range      Date1      Date2  maxDD
0     11/01/2016:07/20/2017 2017-02-22 2017-06-27   0.29
1     11/02/2016:07/21/2017 2017-02-22 2017-06-27   0.29
2     11/03/2016:07/24/2017 2017-02-22 2017-06-27   0.29
3     11/04/2016:07/25/2017 2017-02-22 2017-06-27   0.29
4     11/07/2016:07/26/2017 2017-02-22 2017-06-27   0.29
...

When I ask for nlargest

fiveLargestDD = outputDF['maxDD'].nlargest(n=5)

I just get one column - maxDD. How do I ask to return all the columns except the index?

Upvotes: 1

Views: 519

Answers (2)

sushanth
sushanth

Reputation: 8302

try,

df.loc[fiveLargestDD.index, :]

Upvotes: 0

Niv Dudovitch
Niv Dudovitch

Reputation: 1658

Returns all the columns:

outputDF.nlargest(5, 'maxDD')

Upvotes: 2

Related Questions