I need to sum a column but need to see how much each row has incremented by so that I can plot the sequence on a chart. I am using a loop but on a large dataset with thousands of rows it is very slow. Is there a more efficient pythonesque way to do this?
hh = pd.DataFrame(np.random.randint(0,10,size=(10, 4)), columns=list('ABCD'))
x=0
for i, row in hh.iterrows():
x = row["D"] + x
row['z'] = x
hh.at[i,'z'] = x
print(hh)
So, Z2 = z1+D2
Z3 = z2+D3
z4 = z3+D4 ... and so on
A B C D z
0 7 8 7 9 9.0
1 3 8 7 7 16.0
2 0 4 4 3 19.0
3 7 5 8 3 22.0
4 2 1 6 1 23.0
5 2 0 2 7 30.0
6 5 4 2 7 37.0
7 3 4 0 7 44.0
8 1 3 9 2 46.0
9 9 9 0 8 54.0