DAILY AGGREGATION: ONE VALUE PER CALENDAR DAY

Resample a (sub-daily) time series to daily resolution with dv.times.resample_to_daily_agg – e.g. a daily-mean time series over the record. Days with too few records can be dropped via mincounts_perc.

Part of the diive library: https://github.com/holukas/diive

Load example data

import diive as dv

df = dv.load_exampledata_parquet()
series = df["Tair_f"].copy()

print("Half-hourly input:")
print(f"  Records: {len(series)}")
print(f"  Period:  {series.index.min()} to {series.index.max()}")
  > Loaded .parquet file
/home/docs/checkouts/diive/checkouts/latest/diive/configs/exampledata/exampledat
a_PARQUET_CH-DAV_FP2022.5_2013-2022_ID20230206154316_30MIN.parquet (0.050
seconds).
Half-hourly input:
  Records: 175296
  Period:  2013-01-01 00:15:00 to 2022-12-31 23:45:00

Daily mean

The default aggregation is the mean: one value per calendar day.

daily_mean = dv.times.resample_to_daily_agg(series, agg="mean")

print("\nDaily mean:")
print(f"  Days:  {len(daily_mean)}")
print(f"  Range: {daily_mean.min():.2f} to {daily_mean.max():.2f}")
print(daily_mean.head())
Daily mean:
  Days:  3652
  Range: -19.45 to 22.30
TIMESTAMP_MIDDLE
2013-01-01   -0.744750
2013-01-02   -4.999354
2013-01-03   -3.484708
2013-01-04    0.798646
2013-01-05    0.259750
Freq: D, Name: Tair_f, dtype: float64

Other aggregations

Any method pandas’ Series.agg accepts works (sum, median, min, max, std, …).

daily_max = dv.times.resample_to_daily_agg(series, agg="max")
daily_min = dv.times.resample_to_daily_agg(series, agg="min")

print("\nDaily min/max air temperature:")
print(f"  Coldest day: {daily_min.min():.2f}")
print(f"  Warmest day: {daily_max.max():.2f}")
Daily min/max air temperature:
  Coldest day: -23.10
  Warmest day: 28.71

Require complete days

mincounts_perc drops days that are less complete than the given fraction of the fullest day (1.0 = only fully sampled days are kept).

complete_only = dv.times.resample_to_daily_agg(series, agg="mean", mincounts_perc=1.0)

print("\nDaily mean, fully sampled days only:")
print(f"  Days kept: {len(complete_only)} of {len(daily_mean)}")
Daily mean, fully sampled days only:
  Days kept: 3652 of 3652

Total running time of the script: (0 minutes 0.098 seconds)

Gallery generated by Sphinx-Gallery