I have below data summarized from many csv files.
+----------+-----+------+------+------+
| Date | Loc | Hour | Rain | Wind |
+----------+-----+------+------+------+
| 1-Sep-19 | 1 | 1 | 184 | 65 |
| 1-Sep-19 | 1 | 3 | 126 | 64 |
| 2-Sep-19 | 1 | 1 | 112 | 63 |
| 2-Sep-19 | 1 | 2 | 155 | 0 |
| 2-Sep-19 | 1 | 3 | 186 | 50 |
| 3-Sep-19 | 1 | 2 | 154 | 79 |
| 3-Sep-19 | 1 | 3 | 143 | 61 |
| 1-Sep-19 | 2 | 1 | 187 | 73 |
| 1-Sep-19 | 2 | 2 | 173 | 63 |
| 1-Sep-19 | 2 | 3 | 186 | 63 |
| 3-Sep-19 | 2 | 1 | 172 | 56 |
| 3-Sep-19 | 2 | 2 | 156 | 56 |
| 3-Sep-19 | 2 | 3 | 176 | 79 |
+----------+-----+------+------+------+
Where Random observations for Rain & Wind details of particular Day, Location & Hour is collected.
Note the missing lines in Day, Location & Hour.
I want to fill the missing data with 0 values. My desired final output is as below.
+----------+-----+------+------+------+
| Date | Loc | Hour | Rain | Wind |
+----------+-----+------+------+------+
| 1-Sep-19 | 1 | 1 | 184 | 65 |
| 1-Sep-19 | 1 | 2 | 0 | 0 |
| 1-Sep-19 | 1 | 3 | 126 | 64 |
| 2-Sep-19 | 1 | 1 | 112 | 63 |
| 2-Sep-19 | 1 | 2 | 155 | 0 |
| 2-Sep-19 | 1 | 3 | 186 | 50 |
| 3-Sep-19 | 1 | 1 | 0 | 0 |
| 3-Sep-19 | 1 | 2 | 154 | 79 |
| 3-Sep-19 | 1 | 3 | 143 | 61 |
| 1-Sep-19 | 2 | 1 | 187 | 73 |
| 1-Sep-19 | 2 | 2 | 173 | 63 |
| 1-Sep-19 | 2 | 3 | 186 | 63 |
| 2-Sep-19 | 2 | 1 | 0 | 0 |
| 2-Sep-19 | 2 | 2 | 0 | 0 |
| 2-Sep-19 | 2 | 3 | 0 | 0 |
| 3-Sep-19 | 2 | 1 | 172 | 56 |
| 3-Sep-19 | 2 | 2 | 156 | 56 |
| 3-Sep-19 | 2 | 3 | 176 | 79 |
+----------+-----+------+------+------+
So far i have tried the below code
import pandas as pd
import numpy as np
df = pd.read_csv('data.csv')
d1 = date(2019, 9, 1)
d2 = date(2019, 9, 3)
delta = d2 - d1
# below indexes were created to make the code more dynamic & scalable easily
idx_date = [(d1 + timedelta(days=i)) for i in range(delta.days + 1)]
idx_loc = np.arange(1,3)
idx_hour = np.arange(1,4)
cols =['Rain', 'Wind']
df_filled = df.reindex(index=[idx_date,idx_loc,idx_hour], columns=cols, fill_value=0)
But, I get an error. how to solve this