I have a data frame like that
| week | co_week | Revenue | Cohort_index |
|---|---|---|---|
| 19/09/2021 | 01/10/2021 | 120 | 0 |
| 19/09/2021 | 03/10/2021 | 150 | 1 |
| 19/09/2021 | 06/10/2021 | 223 | 2 |
| 19/09/2021 | 07/10/2021 | 256 | 4 |
| 19/09/2021 | 08/10/2021 | 340 | 5 |
| 20/09/2021 | 06/10/2021 | 126 | 0 |
| 20/09/2021 | 07/10/2021 | 234 | 1 |
Now I'd like to check if one cohort_index is missing (3 in this case) , then insert a new row with the missing index , rest of column values are copied from the previous row while updating the data frame index.
Desired Output :
| week | co_week | Revenue | Cohort_index |
|---|---|---|---|
| 19/09/2021 | 01/10/2021 | 120 | 0 |
| 19/09/2021 | 03/10/2021 | 150 | 1 |
| 19/09/2021 | 06/10/2021 | 223 | 2 |
| 19/09/2021 | 06/10/2021 | 223 | 3 |
| 19/09/2021 | 07/10/2021 | 256 | 4 |
| 19/09/2021 | 08/10/2021 | 340 | 5 |
| 20/09/2021 | 06/10/2021 | 126 | 0 |
| 20/09/2021 | 07/10/2021 | 234 | 1 |
I can't hard-code the new raw since the data is huge!
new_raw = DataFrame({"week": 19/09/2022, "co_week": 06/10/2021, "Revenue": 223 ,"Cohort_index":3})
df = df.append(new_raw, ignore_index=False)