pastas.timeseries_utils.time_weighted_resample#

pastas.timeseries_utils.time_weighted_resample(s: pandas.Series, index: pandas.Index, method: str = 'stepwise', add_first_index: bool = True, require_full_coverage: bool = False)#

Time-weighted resampling of a time series to arbitrary periods.

Parameters:
  • s (pandas.Series) – Original time series with a datetime-like index.

  • index (pandas.Index) – Target time index defining the boundaries of the new periods.

  • method ({"linear", "stepwise", "state", "flux"}, optional) – Interpretation of the original series: - “stepwise” or “flux”: treat values as fluxes, piecewise-constant backfilled. - “linear”, “state” or “stage”: treat values as state variables (stage), interpolate linearly. Default is “stepwise”.

  • add_first_index (bool, optional) – If True, the first index value is added to the resulting series, with a NaN value. This is useful when the resulting series needs to have the same index as the target index. If False, the output series has length len(index)-1 and uses index[1:] as its index. Default is True.

  • require_full_coverage (bool, optional) – If True, periods that are not fully covered by the original data are masked with NaN. If False, only periods completely outside the range of the original data are masked. Default is False.

Raises:

ValueError – If method is not supported or input is not strictly increasing.

Returns:

s_new – Resampled time series. Each value represents the time-weighted mean over the corresponding period. Periods not covered by the original data are NaN.

Return type:

pandas.Series