Assume we have a table looks like the following:
| id | week_num | people | date | level | a | b |
|---|---|---|---|---|---|---|
| 1 | 1 | 20 | 1990101 | 1 | 2 | 3 |
| 1 | 2 | 30 | 1990108 | 1 | 2 | 3 |
| 1 | 3 | 40 | 1990115 | 1 | 2 | 3 |
| 1 | 5 | 100 | 1990129 | 1 | 2 | 3 |
| 1 | 7 | 100 | 1990212 | 1 | 2 | 3 |
week_num skip the "4" and "6" because the corresponding "people" is 0. However, we want the all the rows included like the following table.
| id | week_num | people | date | level | a | b |
|---|---|---|---|---|---|---|
| 1 | 1 | 20 | 1990101 | 1 | 2 | 3 |
| 1 | 2 | 30 | 1990108 | 1 | 2 | 3 |
| 1 | 3 | 40 | 1990115 | 1 | 2 | 3 |
| 1 | 4 | 0 | 1990122 | 1 | 2 | 3 |
| 1 | 5 | 100 | 1990129 | 1 | 2 | 3 |
| 1 | 6 | 0 | 1990205 | 1 | 2 | 3 |
| 1 | 7 | 100 | 1990212 | 1 | 2 | 3 |
The date starts with 1990101, the next row must +7 days if it is a continuous week_num(Ex: 1,2 is continuous; 1,3 is not).
How can we use python(pandas) to achieve this goal?
Note: Each id has 10 week_num(1,2,3,...,10), the output must include all "week_num" with corresponding "people" and "date".
Update: Other columns like "level","a","b" should stay the same even we add the skipped week_num.