I am using python's Jupyter notebook.
So there is a dataset contains monthly data (log) for all observations. The lastest records for all observations are identifying their account have been deactivated. I want to use the value from the previous month (time period) to replace the last period.
To visualize the question, here is an example:
|id|age |level| time |
|--|----|-----|-------|
| 1| 45 | 4 |2019-01|
| 1| 45 | 5 |2019-02|
| 1| 45 | 6 |2019-03|
| 1| 45 | 0 |2019-04|
| 2| 28 | 2 |2018-12|
| 2| 28 | 3 |2019-01|
| 2| 28 | 3 |2019-02|
| 2| 28 | 0 |2019-03|
I want to replace the level 0 for both observation 1 and 2 by the value they have before that. But the latest level not necessarily is 0.
So it should be:
|id|age |level| time |
|--|----|-----|-------|
| 1| 45 | 4 |2019-01|
| 1| 45 | 5 |2019-02|
| 1| 45 | 6 |2019-03|
| 1| 45 | 6 |2019-04|
| 2| 28 | 2 |2018-12|
| 2| 28 | 3 |2019-01|
| 2| 28 | 3 |2019-02|
| 2| 28 | 3 |2019-03|