I think you might have your desired output cumulative sums mixed up(or i don't understand), this output is not the same but i think it could be what you are after.
import pandas as pd df = pd.DataFrame([ ["Gothenburg", "Malmo", 2018, 1, 1], ["Malmo", "Gothenburg", 2018, 1, 1], ["Malmo", "Gothenburg", 2018, 0, 3], ["Gothenburg", "Malmo", 2018, 1, 1], ["Gothenburg", "Malmo", 2018, 0, 3], ["Gothenburg", "Malmo", 2018, 1, 1], ["Gothenburg", "Malmo", 2018, 0, 3], ["Malmo", "Gothenburg", 2018, 0, 3], ["Gothenburg", "Malmo", 2018, 1, 1], ["Malmo", "Gothenburg", 2018, 0, 3], ["Malmo", "Gothenburg", 2018, 1, 1], ["Malmo", "Gothenburg", 2018, 0, 3], ]) df.columns = ['H_team', 'A_team', 'Year', 'H_points', 'A_points'] df['H_cumsum'] = df['H_points'].cumsum().shift(1) df['A_cumsum'] = df['A_points'].cumsum().shift(1) print(df)
Output: H_team A_team Year H_points A_points H_cumsum A_cumsum
0 Gothenburg Malmo 2018 1 1 NaN NaN
1 Malmo Gothenburg 2018 1 1 1.0 1.0
2 Malmo Gothenburg 2018 0 3 2.0 2.0
3 Gothenburg Malmo 2018 1 1 2.0 5.0
4 Gothenburg Malmo 2018 0 3 3.0 6.0
5 Gothenburg Malmo 2018 1 1 3.0 9.0
6 Gothenburg Malmo 2018 0 3 4.0 10.0
7 Malmo Gothenburg 2018 0 3 4.0 13.0
8 Gothenburg Malmo 2018 1 1 4.0 16.0
9 Malmo Gothenburg 2018 0 3 5.0 17.0
10 Malmo Gothenburg 2018 1 1 5.0 20.0
11 Malmo Gothenburg 2018 0 3 6.0 21.0