This is a sample from my pandas df.
| plant | device | quarter | avg_value | |
|---|---|---|---|---|
| 17 | 4962 | 939322103 | 1999Q3 | 3624000.0 |
| 16 | 4962 | 939322103 | 1999Q2 | 4407000.0 |
| 15 | 4962 | 939322103 | 1999Q1 | 5065000.0 |
| 14 | 4962 | 460981301 | 2006Q2 | 390000.0 |
| 13 | 4962 | 460981301 | 2006Q1 | 407000.0 |
| 12 | 4962 | 460981301 | 2005Q4 | 336000.0 |
| 11 | 4962 | 45839N101 | 1999Q3 | 6977000.0 |
| 10 | 4962 | 387241102 | 1999Q3 | 95000.0 |
| 9 | 4962 | 387241102 | 1999Q1 | 57000.0 |
In the row with indexes 10 and 9, for the same device 387241102 I've got the same device reporting data for avg_value for 1999Q1 and 1999Q3. The business logic states that if there is a missing data for one quarter that sits between two quarters that do have avg_value present, then treat this case as missing data and impute it by creating a new row for the missing [plant, device, quarter] combination and copying the avg_value from the latest out of two quarters for the same [plant, device, quarter]. In this case, the copying avg_value from 1999Q3
Meaning, for the case above, I'd need to create a new entry for the 1999Q2 in my pandas df like so.
| plant | device | quarter | avg_value | |
|---|---|---|---|---|
| 4962 | 387241102 | 1999Q2 | 95000.0 |
I'm struggling with identifying these cases with missing quarter sitting in between two that do have the data ... any help would be appreciated.