pyspark.pandas.Series.resample¶

Series.
resample
(rule: str, closed: Optional[str] = None, label: Optional[str] = None, on: Optional[Series] = None) → SeriesResampler[source]¶ Resample timeseries data.
Convenience method for frequency conversion and resampling of time series. The object must have a datetimelike index (only support DatetimeIndex for now), or the caller must pass the label of a datetimelike series/index to the
on
keyword parameter.New in version 3.4.0.
 Parameters
 rulestr
The offset string or object representing target conversion. Currently, supported units are {‘Y’, ‘A’, ‘M’, ‘D’, ‘H’, ‘T’, ‘MIN’, ‘S’}.
 closed{{‘right’, ‘left’}}, default None
Which side of bin interval is closed. The default is ‘left’ for all frequency offsets except for ‘A’, ‘Y’ and ‘M’ which all have a default of ‘right’.
 label{{‘right’, ‘left’}}, default None
Which bin edge label to label bucket with. The default is ‘left’ for all frequency offsets except for ‘A’, ‘Y’ and ‘M’ which all have a default of ‘right’.
 onSeries, optional
For a DataFrame, column to use instead of index for resampling. Column must be datetimelike.
 Returns
 SeriesResampler
See also
DataFrame.resample
Resample a DataFrame.
groupby
Group by mapping, function, label, or list of labels.
Examples
Start by creating a series with 9 one minute timestamps.
>>> index = pd.date_range('1/1/2000', periods=9, freq='T') >>> series = ps.Series(range(9), index=index, name='V') >>> series 20000101 00:00:00 0 20000101 00:01:00 1 20000101 00:02:00 2 20000101 00:03:00 3 20000101 00:04:00 4 20000101 00:05:00 5 20000101 00:06:00 6 20000101 00:07:00 7 20000101 00:08:00 8 Name: V, dtype: int64
Downsample the series into 3 minute bins and sum the values of the timestamps falling into a bin.
>>> series.resample('3T').sum().sort_index() 20000101 00:00:00 3.0 20000101 00:03:00 12.0 20000101 00:06:00 21.0 Name: V, dtype: float64
Downsample the series into 3 minute bins as above, but label each bin using the right edge instead of the left. Please note that the value in the bucket used as the label is not included in the bucket, which it labels. For example, in the original series the bucket
20000101 00:03:00
contains the value 3, but the summed value in the resampled bucket with the label20000101 00:03:00
does not include 3 (if it did, the summed value would be 6, not 3). To include this value, close the right side of the bin interval as illustrated in the example below this one.>>> series.resample('3T', label='right').sum().sort_index() 20000101 00:03:00 3.0 20000101 00:06:00 12.0 20000101 00:09:00 21.0 Name: V, dtype: float64
Downsample the series into 3 minute bins as above, but close the right side of the bin interval.
>>> series.resample('3T', label='right', closed='right').sum().sort_index() 20000101 00:00:00 0.0 20000101 00:03:00 6.0 20000101 00:06:00 15.0 20000101 00:09:00 15.0 Name: V, dtype: float64
Upsample the series into 30 second bins.
>>> series.resample('30S').sum().sort_index()[0:5] # Select first 5 rows 20000101 00:00:00 0.0 20000101 00:00:30 0.0 20000101 00:01:00 1.0 20000101 00:01:30 0.0 20000101 00:02:00 2.0 Name: V, dtype: float64