I have following dataframe in pandas
code tank nozzle_1 nozzle_2 nozzle_var
123 1 1 1 10
123 1 2 2 12
123 2 1 1 10
123 2 2 2 12
I want to calculate cumulative sum of columns nozzle_1 and nozzle_2 grouping over tank. Following is my desired dataframe.
code tank nozzle_1 nozzle_2 nozzle_var nozzle_1_cumsum nozzle_2_cumsum
123 1 1 1 10 1 1
123 1 2 2 12 3 3
123 2 1 1 10 1 1
123 2 2 2 12 3 3
I am getting nozzle_1 and nozzle_2 from following code in pandas
cols= df.columns[df.columns.str.contains(pat='nozzle_\d+$', regex=True)]
How can I calculate cumsum from above list of columns