当前位置:  开发笔记 > 编程语言 > 正文

Pandas df.describe(),是否有可能在没有移调的情况下按行进行?

如何解决《Pandasdf.describe(),是否有可能在没有移调的情况下按行进行?》经验,为你挑选了2个好方法。

Pandas df.describe()是一个非常有用的方法来概述你的df.但是,它按列描述,我希望对行进行概述.有没有办法让它在没有转置df的情况下"by_row"工作?



1> EdChum - Rei..:

使用apply并传递axis=1describe逐行调用:

In [274]:
df = pd.DataFrame(np.random.randn(4,5))
df

Out[274]:
          0         1         2         3         4
0  0.651863  0.738034 -0.477668 -0.561699  0.047500
1 -1.565093 -0.671551  0.537272 -0.956520  0.301156
2 -0.951549  2.177592  0.059961 -1.631530 -0.620173
3  0.277796  0.169365  1.657189  0.713522  1.649386

In [276]:
df.apply(pd.DataFrame.describe, axis=1)

Out[276]:
   count      mean       std       min       25%       50%       75%       max
0      5  0.079606  0.609069 -0.561699 -0.477668  0.047500  0.651863  0.738034
1      5 -0.470947  0.878326 -1.565093 -0.956520 -0.671551  0.301156  0.537272
2      5 -0.193140  1.458676 -1.631530 -0.951549 -0.620173  0.059961  2.177592
3      5  0.893451  0.722917  0.169365  0.277796  0.713522  1.649386  1.657189



2> Igor Fobia..:

EdChum的答案对我不起作用,因为使用apply命令,所有行都是Series;通过使用pd.Series.describe它起作用

df.apply(pd.Series.describe, axis=1)

推荐阅读
360691894_8a5c48
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有