答案 0 :(得分:1)
经过多次评论和提问后,您希望致电sort_values
:
In [25]:
df = pd.DataFrame(np.random.randn(3,5))
df
Out[25]:
0 1 2 3 4
0 0.489902 -0.283736 0.145133 0.554305 1.386065
1 -0.019177 0.166250 -0.610949 1.421608 -1.123981
2 -0.613483 -0.629143 -0.877431 0.558777 -0.021781
In [31]:
df.iloc[-1].sort_values(ascending=False)
Out[31]:
3 0.558777
4 -0.021781
0 -0.613483
1 -0.629143
2 -0.877431
Name: 2, dtype: float64
您可以使用索引值来索引列:
In [32]:
df[df.iloc[-1].sort_values(ascending=False).index]
Out[32]:
3 4 0 1 2
0 0.554305 1.386065 0.489902 -0.283736 0.145133
1 1.421608 -1.123981 -0.019177 0.166250 -0.610949
2 0.558777 -0.021781 -0.613483 -0.629143 -0.877431
答案 1 :(得分:0)
您可以对下面的行列进行排序,
df
Out[98]:
open high low
date
2015/11/26 9861.48 8484.9 4656.74
2015/11/27 9841.48 8384.9 4256.74
df.loc['2015/11/26'].order(ascending=False)
Out[99]:
open 9861.48
high 8484.90
low 4656.74
Name: 2015/11/26, dtype: float64
df.loc['2015/11/26'].order(ascending=True)
Out[100]:
low 4656.74
high 8484.90
open 9861.48
Name: 2015/11/26, dtype: float64