I have a Pandas dataframe where for certain dates certain products are missing. I want to add those rows to the dataframe and assign them a sales value of 0. How can I do that?
# Sample dataframe
import pandas as pd
df = pd.DataFrame({
'date': ['2020-01-01', '2020-01-01', '2020-01-01', '2020-01-02', '2020-01-02', '2020-01-03', '2020-01-03'],
'product': ['glass', 'clothes', 'food', 'glass', 'food', 'glass', 'clothes'],
'sales': [100, 120, 50, 90, 60, 110, 130]
})
date product sales
0 2020-01-01 glass 100
1 2020-01-01 clothes 120
2 2020-01-01 food 50
3 2020-01-02 glass 90
4 2020-01-02 food 60
5 2020-01-03 glass 110
6 2020-01-03 clothes 130
## 'clothes' is missing for 2020-01-02 and 'food' is missing for 2020-01-03
## What I want to get:
date product sales
0 2020-01-01 glass 100
1 2020-01-01 clothes 120
2 2020-01-01 food 50
3 2020-01-02 glass 90
4 2020-01-02 clothes 0
5 2020-01-02 food 60
6 2020-01-03 glass 110
7 2020-01-03 clothes 130
8 2020-01-03 food 0