I have two dataframes, just like below.
Dataframe1:
| country | type | start_week | end_week |
|---|---|---|---|
| 1 | a | 12 | 13 |
| 2 | b | 13 | 14 |
Dataframe2:
| country | type | week | value |
|---|---|---|---|
| 1 | a | 12 | 1000 |
| 1 | a | 13 | 900 |
| 1 | a | 14 | 800 |
| 2 | b | 12 | 1000 |
| 2 | b | 13 | 900 |
| 2 | b | 14 | 800 |
I want to add to the first dataframe column with the mean value from the second dataframe for key (country+type) and between start_week and end_week.
I want desired output to look like the below:
| country | type | start_week | end_week | avg |
|---|---|---|---|---|
| 1 | a | 12 | 13 | 950 |
| 2 | b | 13 | 14 | 850 |