pandas 1.4.2

NotesParametersReturnsBackRef
asfreq(self: 'NDFrameT', freq, method=None, how: 'str | None' = None, normalize: 'bool_t' = False, fill_value=None) -> 'NDFrameT'

Returns the original data conformed to a new index with the specified frequency.

If the index of this Series/DataFrame is a ~pandas.PeriodIndex , the new index is the result of transforming the original index with PeriodIndex.asfreq <pandas.PeriodIndex.asfreq> (so the original index will map one-to-one to the new index).

Otherwise, the new index will be equivalent to pd.date_range(start, end, freq=freq) where start and end are, respectively, the first and last entries in the original index (see pandas.date_range ). The values corresponding to any timesteps in the new index which were not present in the original index will be null ( NaN ), unless a method for filling such unknowns is provided (see the method parameter below).

The resample method is more appropriate if an operation on each group of timesteps (such as an aggregate) is necessary to represent the data at the new frequency.

Notes

To learn more about the frequency strings, please see :None:None:`this link <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`.

Parameters

freq : DateOffset or str

Frequency DateOffset or string.

method : {'backfill'/'bfill', 'pad'/'ffill'}, default None

Method to use for filling holes in reindexed Series (note this does not fill NaNs that already were present):

  • 'pad' / 'ffill': propagate last valid observation forward to next valid

  • 'backfill' / 'bfill': use NEXT valid observation to fill.

how : {'start', 'end'}, default end

For PeriodIndex only (see PeriodIndex.asfreq).

normalize : bool, default False

Whether to reset output index to midnight.

fill_value : scalar, optional

Value to use for missing values, applied during upsampling (note this does not fill NaNs that already were present).

Returns

Series/DataFrame

Series/DataFrame object reindexed to the specified frequency.

Convert time series to specified frequency.

See Also

reindex

Conform DataFrame to new index with optional filling logic.

Examples

Start by creating a series with 4 one minute timestamps.

This example is valid syntax, but we were not able to check execution
>>> index = pd.date_range('1/1/2000', periods=4, freq='T')
... series = pd.Series([0.0, None, 2.0, 3.0], index=index)
... df = pd.DataFrame({'s': series})
... df s 2000-01-01 00:00:00 0.0 2000-01-01 00:01:00 NaN 2000-01-01 00:02:00 2.0 2000-01-01 00:03:00 3.0

Upsample the series into 30 second bins.

This example is valid syntax, but we were not able to check execution
>>> df.asfreq(freq='30S')
                       s
2000-01-01 00:00:00    0.0
2000-01-01 00:00:30    NaN
2000-01-01 00:01:00    NaN
2000-01-01 00:01:30    NaN
2000-01-01 00:02:00    2.0
2000-01-01 00:02:30    NaN
2000-01-01 00:03:00    3.0

Upsample again, providing a fill value .

This example is valid syntax, but we were not able to check execution
>>> df.asfreq(freq='30S', fill_value=9.0)
                       s
2000-01-01 00:00:00    0.0
2000-01-01 00:00:30    9.0
2000-01-01 00:01:00    NaN
2000-01-01 00:01:30    9.0
2000-01-01 00:02:00    2.0
2000-01-01 00:02:30    9.0
2000-01-01 00:03:00    3.0

Upsample again, providing a method .

This example is valid syntax, but we were not able to check execution
>>> df.asfreq(freq='30S', method='bfill')
                       s
2000-01-01 00:00:00    0.0
2000-01-01 00:00:30    NaN
2000-01-01 00:01:00    NaN
2000-01-01 00:01:30    2.0
2000-01-01 00:02:00    2.0
2000-01-01 00:02:30    3.0
2000-01-01 00:03:00    3.0
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.generic.NDFrame.resample pandas.core.generic.NDFrame.fillna

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/generic.py#7581
type: <class 'function'>
Commit: