I have this dataset:
col1 = [1,2,3,4,5,6,7,8]
col2 = [2,3,5,1,4,3,4,5]
df = pd.DataFrame({'Column1': col1, 'Column2': col2})
Column1 Column2
1 2
2 3
3 5
4 1
5 4
6 3
7 4
8 5
I am trying to get it so when the Column2 has stopped increasing that it fills the previous values so the expected output would be:
Column1 Column2
1 5
2 5
3 5
4 4
5 4
6 5
7 5
8 5
I tried doing this by a for loop comparing the previous to the current, but this would require lots of for loops. Is there an efficient way of doing this?