Need help in filling gaps for missing beginning date of a month in df_1 (for example: 01, 02, 05, and 07 to 11), I need to have a continuous months (i.e. 12) .
In: df_1 = pd.DataFrame([['2021-03-01', 'Supp_1', 'Product_1', '1'],
['2021-04-01', 'Supp_1', 'Product_1', 1],
['2021-06-01','Supp_1', 'Product_1', 1],
['2021-12-01', 'Supp_1', 'Product_1', 1.25]],
columns=['Date','Supplier','Product','Cost'])
Out:
Date Supplier Product Cost
0 2021-03-01 Supp_1 Product_1 1
1 2021-04-01 Supp_1 Product_1 1
2 2021-06-01 Supp_1 Product_1 1
3 2021-12-01 Supp_1 Product_1 1.25
Expected result is,
Date Supplier Product Cost
0 2021-01-01 Supp_1 Product_1 1
1 2021-02-01 Supp_1 Product_1 1
2 2021-03-01 Supp_1 Product_1
3 2021-04-01 Supp_1 Product_1
4 2021-05-01 Supp_1 Product_1
5 2021-06-01 Supp_1 Product_1 1
6 2021-07-01 Supp_1 Product_1
7 2021-08-01 Supp_1 Product_1
8 2021-09-01 Supp_1 Product_1
9 2021-10-01 Supp_1 Product_1
10 2021-11-01 Supp_1 Product_1
11 2021-12-01 Supp_1 Product_1 1.25
Once we have the df_2, then I can use ffill() and bfill() to fill the gaps for 'Cost'