I have the following date & price data for some grocery items, with the important note that some of these items have missing records for some months. For example, bread has data for all months of 2022, but juice, among others, has missing values. For example:
bread_dataframe
Date | Price |
---|---|
1/1/22 | 4.2 |
2/1/22 | 4.0 |
3/1/22 | 4.1 |
4/1/22 | 3.1 |
5/1/22 | 2.1 |
... | ... |
juice_dataframe
Date | Price |
---|---|
1/1/22 | 3.2 |
4/1/22 | 4.1 |
5/1/22 | 5.1 |
... | ... |
and so on..
My goal is to create a single dataframe with a date index and columns representing each item, with NaN showing for any month/price item we have no price for. Like so:
Date | Bread | Juice | ... |
---|---|---|---|
1/1/22 | 4.2 | 3.2 | |
2/1/22 | 4.0 | NaN | |
3/1/22 | 4.1 | NaN | |
4/1/22 | 3.2 | 4.1 | |
5/1/22 | 2.1 | 5.1 |
So far, I have tried creating a dictionary of items_dict[item_name] = pd.DataFrame({'Date': dates, 'Price': item_price})
and then using pd.concat(items_dict, axis=1)
but this only returns this sort of dataframe.
Date | ('Bread', 'Price') | ('Juice', 'Price') | ... |
---|---|---|---|
1/1/22 | |||
2/1/22 | |||
3/1/22 | |||
4/1/22 | |||
5/1/22 |
Any help is much appreciated.