我有一个数据帧,有很多列,其中有很多整数值。我想返回列的名称,作为行中第二低的值。你知道吗
我可以返回一行中最低值的列名,非常简单:
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
谢谢你的支持。你知道吗
使用^{} 作为按排序值排列的所有列名的数组:
然后通过索引选择
'columns'
,并传递给Series
构造函数:相关问题 更多 >
编程相关推荐