You can use nlargest
/nsmallest
-
df
a b
0 3.0 1.0
1 2.0 4.0
2 4.0 2.0
3 1.0 3.0
df.a.nlargest(3).iloc[-1]
2.0
Or,
df.a.nlargest(3).iloc[[-1]]
1 2.0
Name: a, dtype: float64
And, as for b
-
df.b.nsmallest(2).iloc[-1]
2.0
Or,
df.b.nsmallest(2).iloc[[-1]]
2 2.0
Name: b, dtype: float64
Quick observation here - this sort of operation cannot be vectorised. You are essentially performing two completely different operations here.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…