1

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|
Simon
  • 11
  • 3
  • Sorry I didn't make my question clear. The question is really to use the previous value to replace the latest one. Not simply replace 0 with the rest. – Simon Aug 05 '19 at 13:53

1 Answers1

0

You can read your dates out of the file one by one and creating a datetime-object.

You can compare the datetime object afterwards if its inside the interval with:

start_date_interval <= date_of_dataset <= end_date_interval

If the statement returns true, you can extract the Data from the file and proceed with your calculation.

BTW: Your Question and your Description differ while reading. So its difficult to give a proper answer if the question is different.