I have the following dataframe:
index = range(14) data = [1, 0, 0, 2, 0, 4, 6, 8, 0, 0, 0, 0, 2, 1] df = pd.DataFrame(data=data, index=index, columns = [\'A\
This is a better answer to the previous one, since the previous answer returns a dataframe which hides all zero values.
Instead, if you use the following line of code -
df['A'].mask(df['A'] == 0).ffill(downcast='infer')
Then this resolves the problem. It replaces all 0 values with previous values.