2

I have the following dataframe (top 30 lines shown, its weather station data at 5 minute intervals, 2 years of data) and need to resample it into days with mean values for each column, I also need to get the min and max of 'hum' and 'temp' columns for each day. I can do the mean resample using

davis['datetime']=pd.to_datetime(davis['datetime']) #convert datetime str to datetime
davis.index=davis['datetime']#set index to datetime
davis.drop(columns=['datetime'], inplace=True#remove 'datetime' column
davisdaily=davis.resample('1d', offset='1d').mean()#resample and calculate daily mean

But can't figure out how to get the min and max values for each day.

                     hum  wind_speed_avg_last_10_min  rainfall_daily_mm  temp
datetime                                                                      
2021-06-17 15:30:42  67.2                        7.37                0.0  64.2
2021-06-17 15:35:42  67.5                        6.68                0.0  64.8
2021-06-17 15:40:42  65.5                        7.31                0.0  64.6
2021-06-17 15:45:42  65.5                        7.87                0.0  64.7
2021-06-17 15:50:42  62.6                        8.12                0.0  64.6
2021-06-17 15:55:42  63.9                        7.50                0.0  64.9
2021-06-17 16:00:42  62.5                        6.06                0.0  64.6
2021-06-17 16:05:42  61.7                        6.93                0.0  64.6
2021-06-17 16:10:42  60.5                        6.81                0.0  64.9
2021-06-17 16:15:42  61.2                        6.56                0.0  64.9
2021-06-17 16:20:42  62.1                        6.25                0.0  65.1
2021-06-17 16:25:42  63.5                        6.50                0.0  65.1
2021-06-17 16:30:42  59.4                        6.68                0.0  65.0
2021-06-17 16:35:42  58.6                        8.06                0.0  64.9
2021-06-17 16:40:42  58.8                        8.18                0.0  65.0
2021-06-17 16:45:42  59.6                        8.06                0.0  64.9
2021-06-17 16:50:42  59.9                        7.31                0.0  64.9
2021-06-17 16:55:42  57.5                        7.93                0.0  64.7
2021-06-17 17:00:42  57.4                        7.56                0.0  64.3
2021-06-17 17:05:42  57.3                        6.81                0.0  64.5
2021-06-17 17:10:42  57.2                        8.00                0.0  63.8
2021-06-17 17:15:42  56.5                        7.93                0.0  64.2
2021-06-17 17:20:42  54.8                        7.75                0.0  63.8
2021-06-17 17:25:42  57.1                        8.81                0.0  63.6
2021-06-17 17:30:42  58.1                        8.81                0.0  63.4
2021-06-17 17:35:42  56.2                        8.12                0.0  63.1
2021-06-17 17:40:42  55.6                        7.87                0.0  63.0
2021-06-17 17:45:42  55.6                        8.37                0.0  62.7
2021-06-17 17:50:42  56.7                        8.43                0.0  62.8
2021-06-17 17:55:42  55.3                        8.37                0.0  62.7
matt cooper
  • 101
  • 1
  • 8

1 Answers1

2

to get min and max for each day, you can simply use agg() method after resampling with mean like

min_max = davis.resample('1d', offset='1d').agg({'hum': ['min', 'max'], 'temp': ['min', 'max']})