dataframe.sum()函数

官方帮助文档解释;

DataFrame.sum(axis=Noneskipna=Nonelevel=Nonenumeric_only=None**kwargs)

axis : {index (0), columns (1)},axis=0代表对列进行求和,axis=1代表对行进行求和。

调用DataFrame的sum方法将会返回一个含有列小计的Series:传入axis=1将会按行进行求和运算:

[html] view plain copy
  1. In [111]: df  
  2. Out[111]:   
  3.     one  two  
  4. a  1.40  NaN  
  5. b  7.10 -4.5  
  6. c   NaN  NaN  
  7. d  0.75 -1.3  
[python] view plain copy
  1.   
[python] view plain copy
  1. In [112]: df.sum()  
  2. Out[112]:   
  3. one    9.25  
  4. two   -5.80  
[python] view plain copy
  1.   
[python] view plain copy
  1. In [113]: df.sum(axis=1)  
  2. Out[113]:   
  3. a    1.40  
  4. b    2.60  
  5. c     NaN  
  6. d   -0.55  
  7. dtype: float64 

猜你喜欢

转载自www.cnblogs.com/ziheIT/p/8972887.html