import pandas as pd
df = pd.DataFrame({'a': [1, 2, 0, 0, 0, -1, -5, 1, 1, 2, 0, 0, 0, 0, -5, 0, 0, 0, 0, 0, 0, 0, 3, -2],
'b': [1, 3, 3, 3, 3, 2, 0, 1, 2, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1]})
I have a dataframe with a column is 'a'. And I want to get a column 'b' from column 'a'.
I have used "pd.cumsum" and dealt with the results, but I can not get the expected result. I don't want to use "for loop". I don't know how to use pandas to solve my problem. Please help me, thanks!