我有一个包含大量整数值的列的数据框。我想返回该行第二小的值所在的列名。
我可以返回该行最小值所在的列名,这很简单:
感谢您的支持。
我可以返回该行最小值所在的列名,这很简单:
import pandas as pd
matrix = [(22, 2, 13),
(9, 1, 5),
(5, 4, 3),
(6, 3, 1),
(1, 2, 20)]
dfObj = pd.DataFrame(matrix, index=list('abcde'), columns=list('xyz'))
minValueIndexObj = dfObj.idxmin(axis=1)
print("min values of row are at following columns :")
print(minValueIndexObj)
Out[]:
min values of row are at following columns :
a y
b y
c z
d z
e x
dtype: object
第 a 行中,y 列的数值最小。
接下来我需要的是:
2nd min values of row are at following columns :
a z
b z
c y
d y
e y
dtype: object
感谢您的支持。
dfObj[2nd] = a[:,1]
,对吗? - Audiogotta -> y; y -> 2
。 - Audiogott