pandas.Timestamp.to_period#

Timestamp.to_period(freq=None)#

Return an period of which this timestamp is an observation.

This method converts the given Timestamp to a Period object, which represents a span of time,such as a year, month, etc., based on the specified frequency.

Parameters:
freqstr, optional

Frequency string for the period (e.g., ‘Y’, ‘M’, ‘W’). Defaults to None.

See also

Timestamp

Represents a specific timestamp.

Period

Represents a span of time.

to_period

Converts an object to a Period.

Examples

>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651')
>>> # Year end frequency
>>> ts.to_period(freq='Y')
Period('2020', 'Y-DEC')
>>> # Month end frequency
>>> ts.to_period(freq='M')
Period('2020-03', 'M')
>>> # Weekly frequency
>>> ts.to_period(freq='W')
Period('2020-03-09/2020-03-15', 'W-SUN')
>>> # Quarter end frequency
>>> ts.to_period(freq='Q')
Period('2020Q1', 'Q-DEC')