官方API给的解释如下
axis : {0 or ‘index’, 1 or ‘columns’}, default 0
The index or the name of the axis. 0 is equivalent to None or ‘index’.
就是说axis默认值为0,可设成0或1两个值
当axis=1时,是按列累加和的,例子如下:
import pandas as pd
fs = pd.DataFrame([[2.0, 1.0,3.0,5],
[3.0, 4.0,5.0,5],
[3.0, 4.0,5.0,5],
[1.0, 0.0,6.0,5]],
columns = list('ABCD'))
print(fs.cumsum(axis=1))
运行结果如下:
A0表示0行A列
即分别是A0,A0+B0,A0+B0+C0,A0+B0+C0+D0
当axis=0时按行(或者说索引 Index)累加和
import pandas as pd
fs = pd.DataFrame([[2.0, 1.0,3.0,5],
[3.0, 4.0,5.0,5],
[3.0, 4.0,5.0,5],
[1.0, 0.0,6.0,5]],
columns = list('ABCD'))
print(fs.cumsum(axis=0))
运行结果如下:
即
A0
A0+A1
A0+A1+A2
A0+A1+A2+A3