Pandas DataFrame: resample() function
DataFrame - resample() function
The resample() function is used to resample time-series data.
Syntax:
DataFrame.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)
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 Default Value: 0 |
Optional |
Returns: Resampler object
Example:
Download the Pandas DataFrame Notebooks from here.
Previous: DataFrame - shift() function
Next: DataFrame - tz_localize() function
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/pandas/dataframe/dataframe-resample.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics