Friday, 22 November 2019

how can i create new rows in this pandas dataframe?

i have a scenario in which i have a data frame which contains 4 columns ( date, product, store and sales_amt)

date, product, store, sales_amt

1/1/2019, A,A,200

1/1/2019,A,B,120

1/2/2019, A,A,75

1/3/2019,A,A,69

1/3/2019,A,B,23

--

--

1/31/2019,A,B,49

the dates are supposed to span a whole month ( eg in this case, january 2019) but there are some missing days in the data frame.

does anyone have any tips on python code that can loop through the dates for a particular month and add a new row to the data frame with the missing date, product/store combination and a sales_amt of zero?

For example, there is no entry for the product/store combination of A/B on 1/2/2019

Goal at the end is to have an entry for every day of that month for every product/store combination.

how best can i do this?



from how can i create new rows in this pandas dataframe?

No comments:

Post a Comment