Skip to content
Advertisement

Pandas fill in missing dates in DataFrame with multiple columns

I want to add missing dates for a specific date range, but keep all columns. I found many posts using afreq(), resample(), reindex(), but they seemed to be for Series and I couldn’t get them to work for my DataFrame.

Given a sample dataframe:

JavaScript

My goal is to return below; filling in qty as 0, but fill other columns. Of course, I have many other ids. I would like to be able to specify the start/end dates to fill; this example uses 3/7 to 3/21.

JavaScript

How can I keep the remainder of my DataFrame intact?

Advertisement

Answer

In you case , you just need do with unstack and stack + reindex

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement