you are better than you think

pandas sum函数小结

· by thur · Read in about 1 min · (42 Words)
python pandas sum

sum()函数文档中说sum的作用是Return the sum of the values for the requested axis ,即返回指定栏或列的值的和。

函数有4个有名参数, axis=None, skipna=None, level=None, numeric_only=None, **kwargs 。 不指定任何参数时即给axis赋值。

当sum(1)时是求行的和,当sum(0)时是求列的和。理解这个用法时参考了这个链接:http://blog.mathandpencil.com/column-and-row-sums/  

If you want to do a row sum in pandas, given the dataframe df:

python df.sum(axis=1)

and a column sum:

python df.sum(axis=0)

Comments