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: dt.to_period() function

Series.dt.to_period() function

Cast to PeriodArray/Index at a particular frequency.

Converts DatetimeArray/Index to PeriodArray/Index.

Syntax:

Series.dt.to_period(self, *args, **kwargs)

Parameter:

Name Description Type / Default Value Required / Optional
freq One of pandas’ offset strings or an Offset object. Will be inferred by default. str or Offset Optional

Returns: PeriodArray/Index

Raises: ValueError
When converting a DatetimeArray/Index with non-regular values, so that a frequency cannot be inferred.

Example:


Download the Pandas Series Notebooks from here.

Previous: Series.dt.is_leap_year() function
Next: Series.dt.to_pydatetime() function