Skip to content
Advertisement

Calculate average temperature/humidity between 2 dates pandas data frames

I have the following data frames: df3

Harvest_date Starting_date
2022-10-06 2022-08-06
2022-02-22 2021-12-22

df (I have all temp and humid starting from 2021-01-01 till the present)

date temp humid
2022-10-06 00:30:00 2 30
2022-10-06 00:01:00 1 30
2022-10-06 00:01:30 0 30
2022-10-06 00:02:00 0 30
2022-10-06 00:02:30 -2 30

I would like to calculate the avg temperature and humidity between the starting_date and harvest_date. I tried this:

JavaScript

I get the same value for all dates. Can someone point out what I did wrong, please?

Advertisement

Answer

Use DataFrame.loc with match indices by means of another DataFrame:

JavaScript

EDIT: For add new condition for match by room columns use:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement