0

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.

  • Does this answer your question? [Moving Average Pandas](https://stackoverflow.com/questions/40060842/moving-average-pandas) – KodornaRocks Aug 31 '21 at 17:18
  • Not really. The problem is that I have different numbers of measurements per day. So on one day the temperature was measured every ten minutes and the next day every 15. – Florian Röhrig Aug 31 '21 at 17:27

0 Answers0