I have two dataframes. The first one has timepoints and values for different measurements. df1:
time | valueX | valueY |
---|---|---|
2021-05-05 11:27:25 | 10 | 3 |
2021-06-05 11:27:25 | 15 | 5 |
and a second dataframe with a lot of temperature measurements. df2:
time | temp |
---|---|
2021-05-05 11:25:25 | 20.1 |
2021-05-05 11:35:25 | 20.2 |
2021-05-05 11:45:25 | 20.1 |
2021-05-05 11:55:25 | 21.2 |
2021-05-05 12:05:25 | 20.1 |
I would like to have another column in df1 that gives me the mean temperature of the last 3 days for the timepoint in column 1 of df1. And I have no glue how to do that... I tried something like this
df1['mean_tepm'] = df2[(df1['time']-df2['time'] < timedelta(days=3) & (df2[(df1['time']-df2['time'] < timedelta(days=0)]['temperature'].mean()
But it gave me the same value for every row.