I have a dataset
id year sales
1 2000 10
2 2000 10
2 2001 20
2 2002 30
I want to create a balanced panel so that I get the following:
id year sales
1 2000 10
1 2001 NA
1 2002 NA
2 2000 10
2 2001 20
2 2002 30
I tried the the following code:
df_balanced = (df.set_index('year',append=True).reindex(pd.MultiIndex.from_product([df.index.unique(),range(df.year.min(),df.year.max()+1)],names['id','year'])).reset_index(level=1))
But I am not getting the desired output.