给出以下示例:
from statistics import stdev
d = pd.DataFrame({"a": [45, 55], "b": [5, 95], "c": [30, 70]})
stds = [stdev(d[c]) for c in d.columns]
有输出:
In [87]: d
Out[87]:
a b c
0 45 5 30
1 55 95 70
In [91]: stds
Out[91]: [7.0710678118654755, 63.63961030678928, 28.284271247461902]
我希望能够按标准差对数据框的列进行排序,结果如下
b c a
0 5 30 45
1 95 70 55
您正在寻找:
d.iloc[:,(-d.std()).argsort()]
Out[8]:
b c a
0 5 30 45
1 95 70 55
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句