I have a pandas df like this:
import pandas as pd
df = pd.DataFrame({'sales':[114,114,114,113,12,10,8500,8666]})
It is cumulative data from sales. There is a bug in the data : Some observations are wrong. (No value can be greater than the previous one : i.e., 8500 and 8666 are not correct) I want to replace these values with the previous one.
I tried this
df['above'] = df.sales.shift(1)
df.loc[df.above < df.sales, 'sales'] = df.above
But this code works only one time, how to extend this code to replace all values until the end of the series (with the previous one) ?
The desired result should looks like :