I have a Pandas data frame that looks like this:
Date | Total Absences | |
---|---|---|
17 | 2022-01-03 | 7 |
18 | 2022-01-04 | 16 |
19 | 2022-01-05 | 18 |
20 | 2022-01-07 | 18 |
and so on.....
As this data only has information from weekdays and I would like to do a time series analysis which requires regularity in the time intervals, I am looking to Pad the missing values with a 0.
However, when I run the below code, it results in an empty data frame:
#As the data doesn't have regular intervals, for example, weekends and holidays, we will need to pad those values.
all_dates = pd.date_range(2022-1-1, 2022-5-31, freq = "D")
data.index = pd.DatetimeIndex(data.index)
data = data.reindex(all_dates, fill_value=0)
print(data)
This is the output:
The desired Output is this:
Date | Total Absences | |
---|---|---|
17 | 2022-01-01 | 0 |
18 | 2022-01-02 | 0 |
19 | 2022-01-03 | 7 |
20 | 2022-01-04 | 16 |
21 | 2022-01-05 | 18 |
22 | 2022-01-06 | 0 |
23 | 2022-01-07 | 18 |
Please let me know where I am going wrong. Thanks.