modin.pandas.DatetimeIndex.to_period¶
- DatetimeIndex.to_period(freq=None) Index [source] (https://github.com/snowflakedb/snowpark-python/blob/v1.26.0/snowpark-python/src/snowflake/snowpark/modin/plugin/extensions/datetime_index.py#L1440-L1483)¶
Cast to PeriodArray/PeriodIndex at a particular frequency.
Converts DatetimeArray/Index to PeriodArray/PeriodIndex.
- Parameters:
freq (str or Period, optional) – One of pandas’ period aliases or a Period object. Will be inferred by default.
- Return type:
PeriodArray/PeriodIndex
- Raises:
ValueError – When converting a DatetimeArray/Index with non-regular values, so that a frequency cannot be inferred.
See also
PeriodIndex
Immutable ndarray holding ordinal values.
DatetimeIndex.to_pydatetime
Return DatetimeIndex as object.
Examples
>>> df = pd.DataFrame({"y": [1, 2, 3]}, ... index=pd.to_datetime(["2000-03-31 00:00:00", ... "2000-05-31 00:00:00", ... "2000-08-31 00:00:00"])) >>> df.index.to_period("M") PeriodIndex(['2000-03', '2000-05', '2000-08'], dtype='period[M]')
Infer the daily frequency
>>> idx = pd.date_range("2017-01-01", periods=2) >>> idx.to_period() PeriodIndex(['2017-01-01', '2017-01-02'], dtype='period[D]')