累积列数据框

时间:2020-10-01 12:21:44

标签: python cumulative-sum

enter image description here

df ['交易量累计'] = df ['Positive_Negative_Volume']。cumsum()

我无法在右列获得正确的累计金额

enter image description here

1 个答案:

答案 0 :(得分:0)

我认为这不会帮助您解决问题,但请看一下此内容-

import pandas as pd

values = [5643397.6053299,
          3496291.56664438,
          -5480337.35603218,
          12944037.55061038,
          6574092.80269061,
          -5331202.45221019,
          -4508747.90607631,
          5609366.20613776,
          4719385.57010436,
          -4840785.79801116,
          4149434.68258942,
          -6587934.91085111,
          12442827.1189019]
df = pd.DataFrame(data={'values': values})
print(df['values'].cumsum().values)
输出
[ 5643397.6053299   9139689.17197428  3659351.8159421  16603389.36655248
 23177482.16924309 17846279.7170329  13337531.81095659 18946898.01709435
 23666283.58719871 18825497.78918755 22974932.47177697 16386997.56092586
 28829824.67982776]

我建议您运行df.dtypesdf.describe(),这可以帮助查明问题所在