I am working on a dataframe pandas that look like that :
Product_id month sales
1 01-2018 25
1 02-2018 34
1 03-2018 29
1 04-2018 45
2 02-2018 3
2 04-2018 2
The sales are between 01-2018 and 09-2020. But my product 2 hasn't be sold in 03-2018. So I am trying to add a row with Product_id 2, month = 03-2018 and sales =0. I don't want to add a row for 01-2018 because if the first sale are in 2018-02, it means that the product wasn't available in 01-2018.
I've got the month of the first sale by products with this code :
df.groupby('Product_id').month.min().reset_index()
Now I'm trying to add rows for each product for each month if the data doesn't exist. I've got nothing that work well yet. Any idea will be welcomed.
Thanks in advance (and sorry for my approximate english!!)
Product_idlike in my answer?