Note
Pandas (51) 본문
728x90
How to get the row number of the nth largest value in a column?
# Input
df = pd.DataFrame(np.random.randint(1, 30, 30).reshape(10,-1), columns=list('abc'))
# Solution
n = 5
df['a'].argsort()[::-1][n]
# output
a b c
0 27 7 25
1 8 4 20
2 1 7 17
3 24 9 17
4 21 15 9
5 21 16 20
6 19 27 25
7 12 8 20
8 11 16 28
9 24 13 4
4
'Pandas' 카테고리의 다른 글
Pandas (52) (1) | 2022.09.21 |
---|---|
Pandas (53) (0) | 2022.09.20 |
Pandas (50) (0) | 2022.09.16 |
Pandas (49) (0) | 2022.09.15 |
Pandas (48) (0) | 2022.09.14 |
Comments