If new row values depend on previous row values as in the op, then depending on the number of columns, it might be better to loop over a pre-initialized dataframe of zeros or grow a python. I was searching on this link before finding this answer. I did not find the solution in the link because i was looking for newline or new line instead of line feed.