pandas df.describe(),是否可以逐行执行而不进行转置? [英] Pandas df.describe() , is it possible to do it by row without transposing?
本文介绍了 pandas df.describe(),是否可以逐行执行而不进行转置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Pandas df.describe() 是查看df的非常有用的方法.但是,它按列进行描述,而我想对行进行概述.有什么方法可以使它在不移置df的情况下"by_row"工作?
Pandas df.describe() is a very useful method to have an overview of your df. However, it describes by columns and I would like to have an overview of the rows instead. Is there any way to make it work "by_row" without transposing the df?
推荐答案
使用apply
并传递axis=1
来逐行调用describe
:
Use apply
and pass axis=1
to call describe
row-wise:
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
这篇关于 pandas df.describe(),是否可以逐行执行而不进行转置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文