我有以下的(簡化)數據幀:返回n個最小通過使用列大熊貓指標
df = pd.DataFrame({'X': [1, 2, 3, 4, 5,6,7,8,9,10],
'Y': [10,20,30,40,50,-10,-20,-30,-40,-50],
'Z': [20,18,16,14,12,10,8,6,4,2]},index=list('ABCDEFGHIJ'))
其中給出以下幾點:
X Y Z
A 1 10 20
B 2 20 18
C 3 30 16
D 4 40 14
E 5 50 12
F 6 -10 10
G 7 -20 8
H 8 -30 6
I 9 -40 4
J 10 -50 2
我想創建一個新的數據框返回索引n列中最小的值。
所需的輸出(比如,3個最小值):
X Y Z
0 A J J
1 B I I
2 C H H
什麼是做到這一點的最好方法是什麼?