1. 程式人生 > >dataframe.sum()函數

dataframe.sum()函數

eric span https python 一個 blog itl skip html

官方幫助文檔解釋;

DataFrame.sum(axis=None, skipna=None, level=None, numeric_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
[python] view plain copy
  1. In [112]: df.sum()
  2. Out[112]:
  3. one 9.25
  4. two -5.80
[python] view plain copy
[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

dataframe.sum()函數