Series.dt
can be used to access series values as datetimelike and return multiple properties. Series.dt.to_period()
Pandas Series.dt.to_period()
basic data of this Series object in PeriodArray / Index with a specific frequency.
Syntax: Series.dt.to_period (* args, ** kwargs)
Parameter:
freq: string or Offset, optional
Returns: PeriodArray / Index
Example # 1: Use Series.dt.to_period ()
to index the underlying data of this series object at weekly frequency.
|
Output:
We will now use Series.dt.to_period ()
to index the underlying data of this series object with weekly frequency.
|
Output:
As we can see in the output, Series.dt.to_period ()
successfully Series .dt.to_period ()
data to target frequency.
Example # 2: Use Series.dt.to_period ()
to cast the base data of this series object into a biennial index.
|
Output:
Now we will use Series.dt.to_period ()
to cast b the baseline data of this series object into a biennial index.
|
Output:
As we can see in the output, Series.dt.to_period ()
successfully Series.dt.to_period ()
data to target frequency.