Pandas's DataFrame multiline summation problem.

< H2 > Development environment < / H2 >

python 3.6
pandas 0.23.3

has a DataFrame, as follows:

import pandas as pd
arr = [[10,10,1],[22,24.2,1.1],[15,15,1],[9,8.1,0.9],[50,55,1.1]]
df = pd.DataFrame(arr,columns=["volume","amount","price"])
    volume  amount  price
0      10    10.0    1.0
1      22    24.2    1.1
2      15    15.0    1.0
3       9     8.1    0.9
4      50    55.0    1.1

requires the sum of each row of the volume column to get the total column

    volume  amount  price  total
0      10    10.0    1.0    10.0
1      22    24.2    1.1    32.0
2      15    15.0    1.0    47.0
3       9     8.1    0.9    56.0
4      50    55.0    1.1    106.0

my current way of writing:

for index in df.index:
     num = df[df.index < index]["volume"].sum()
     df.loc["total"] = num

is there a better way to turn to the gods?

Aug.05,2021

df['total'] = df['volume'].cumsum()
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf4a7c-31f0c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf4a7c-31f0c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?