Convert time series to specified frequency. Returns the original data conformed to a new index with the specified frequency. If the index of this Series/DataFrame is a :class:`~pandas.PeriodIndex`, the new index is the result of transforming the original in
(
self,
freq: Frequency,
method: FillnaOptions | None = None,
how: Literal["start", "end"] | None = None,
normalize: bool = False,
fill_value: Hashable | None = None,
)
| 8772 | |
| 8773 | @final |
| 8774 | def asfreq( |
| 8775 | self, |
| 8776 | freq: Frequency, |
| 8777 | method: FillnaOptions | None = None, |
| 8778 | how: Literal["start", "end"] | None = None, |
| 8779 | normalize: bool = False, |
| 8780 | fill_value: Hashable | None = None, |
| 8781 | ) -> Self: |
| 8782 | """ |
| 8783 | Convert time series to specified frequency. |
| 8784 | |
| 8785 | Returns the original data conformed to a new index with the specified |
| 8786 | frequency. |
| 8787 | |
| 8788 | If the index of this Series/DataFrame is a :class:`~pandas.PeriodIndex`, the |
| 8789 | new index is the result of transforming the original index with |
| 8790 | :meth:`PeriodIndex.asfreq <pandas.PeriodIndex.asfreq>` (so the original index |
| 8791 | will map one-to-one to the new index). |
| 8792 | |
| 8793 | Otherwise, the new index will be equivalent to ``pd.date_range(start, end, |
| 8794 | freq=freq)`` where ``start`` and ``end`` are, respectively, the min and |
| 8795 | max entries in the original index (see :func:`pandas.date_range`). The |
| 8796 | values corresponding to any timesteps in the new index which were not present |
| 8797 | in the original index will be null (``NaN``), unless a method for filling |
| 8798 | such unknowns is provided (see the ``method`` parameter below). |
| 8799 | |
| 8800 | The :meth:`resample` method is more appropriate if an operation on each group of |
| 8801 | timesteps (such as an aggregate) is necessary to represent the data at the new |
| 8802 | frequency. |
| 8803 | |
| 8804 | Parameters |
| 8805 | ---------- |
| 8806 | freq : DateOffset or str |
| 8807 | Frequency DateOffset or string. |
| 8808 | method : {'backfill'/'bfill', 'pad'/'ffill'}, default None |
| 8809 | Method to use for filling holes in reindexed Series (note this |
| 8810 | does not fill NaNs that already were present): |
| 8811 | |
| 8812 | * 'pad' / 'ffill': propagate last valid observation forward to next |
| 8813 | valid based on the order of the index |
| 8814 | * 'backfill' / 'bfill': use NEXT valid observation to fill. |
| 8815 | how : {'start', 'end'}, default end |
| 8816 | For PeriodIndex only (see PeriodIndex.asfreq). |
| 8817 | normalize : bool, default False |
| 8818 | Whether to reset output index to midnight. |
| 8819 | fill_value : scalar, optional |
| 8820 | Value to use for missing values, applied during upsampling (note |
| 8821 | this does not fill NaNs that already were present). |
| 8822 | |
| 8823 | Returns |
| 8824 | ------- |
| 8825 | Series/DataFrame |
| 8826 | Series/DataFrame object reindexed to the specified frequency. |
| 8827 | |
| 8828 | See Also |
| 8829 | -------- |
| 8830 | reindex : Conform DataFrame to new index with optional filling logic. |
| 8831 |