I have a dataframe, df, where I would like to fill in missing date values, as well as missing ids. I also have a few id values that I would like to add into the dataframe, such as 'dd', 'ee' and so on.
Data
id date pwr
aa Q1.22 10
aa Q1.22 1
aa Q2.22 1
aa Q2.22 5
bb Q1.22 5
bb Q1.22 1
bb Q2.22 1
bb Q2.22 1
cc Q1.22 2
cc Q2.22 2
Desired
id date pwr
aa Q1.22 10
aa Q1.22 1
aa Q2.22 1
aa Q2.22 5
aa Q3.22
aa Q4.22
bb Q1.22 5
bb Q1.22 1
bb Q2.22 1
bb Q2.22 1
bb Q3.22
bb Q4.22
cc Q1.22 2
cc Q2.22 2
cc Q3.22
cc Q4.22
dd Q1.22
dd Q2.22
dd Q3.22
dd Q4.22
Doing
I believe I have to establish a range, but not sure how to include the dates if they are quarters. I am still researching. Any suggestion is appreciated.
r = pd.date_range(start=df.dt.min(), end=df.dt.max())
df.set_index('dt').reindex(r).fillna(0.0).rename_axis('dt').reset_index()