Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

Pandas Series: resample() function

Resample Pandas time-series data

The resample() function is used to resample time-series data.

Convenience method for frequency conversion and resampling of time series. Object must have a datetime-like index (DatetimeIndex, PeriodIndex, or TimedeltaIndex), or pass datetime-like values to the on or level keyword.

Syntax:

Series.resample(self, rule, how=None, axis=0, fill_method=None, closed=None, label=None, convention='start', kind=None, loffset=None, limit=None, base=0, on=None, level=None)
Pandas Series resample image

Parameters:

Name Description Type/Default Value Required / Optional
rule   The offset string or object representing target conversion.  DateOffset, Timedelta or str Required
axis Which axis to use for up- or down-sampling. For Series this will default to 0, i.e. along the rows. Must be DatetimeIndex, TimedeltaIndex or PeriodIndex. {0 or ‘index’, 1 or ‘columns’}
Default Value: 0
Required
closed Which side of bin interval is closed. The default is ‘left’ for all frequency offsets except for ‘M’, ‘A’, ‘Q’, ‘BM’, ‘BA’, ‘BQ’, and ‘W’ which all have a default of ‘right’. {‘right’, ‘left’}
Default Value: None
Required
label Which bin edge label to label bucket with. The default is ‘left’ for all frequency offsets except for ‘M’, ‘A’, ‘Q’, ‘BM’, ‘BA’, ‘BQ’, and ‘W’ which all have a default of ‘right’. {‘right’, ‘left’}
Default Value: None
Required
convention For PeriodIndex only, controls whether to use the start or end of rule. {‘start’, ‘end’, ‘s’, ‘e’}
Default Value: ‘start’
Required
kind Pass ‘timestamp’ to convert the resulting index to a DateTimeIndex or ‘period’ to convert it to a PeriodIndex. By default the input representation is retained. {‘timestamp’, ‘period’}
Default Value: None
Optional
loffset Adjust the resampled time labels. timedelta
Default Value: None
Required
base For frequencies that evenly subdivide 1 day, the “origin” of the aggregated intervals. For example, for ‘5min’ frequency, base could range from 0 through 4. Defaults to 0. int
Default Value: 0
Required
on For a DataFrame, column to use instead of index for resampling. Column must be datetime-like. str
Optional
level For a MultiIndex, level (name or number) to use for resampling. level must be datetime-like.  str or int
Optional

Returns: Resampler object

Example:


Download the Pandas Series Notebooks from here.

Previous: Series shift() function
Next: Localize tz-naive index of a Pandas Series