pandas.Period.to_timestamp#
- Period.to_timestamp(freq=None, how='start')#
Return the Timestamp representation of the Period.
Uses the target frequency specified at the part of the period specified by how, which is either the start or the end.
If possible, gives microsecond-unit Timestamp. Otherwise gives nanosecond unit.
- Parameters:
- freqstr or DateOffset, optional
Target frequency. By default the result is exactly the start (or end) of each period. With
how="start", the result is the start ofasfreq(freq, how="start"), except that afreqcoarser than daily gives midnight on that period’s last day, soto_timestamp("M")gives month-end dates. Withhow="end",freqonly affects the resolution (‘ns’ gives nanosecond unit).- how{‘start’, ‘end’, ‘s’, ‘e’}, default ‘start’
Whether to use the start or end of the period. Case-insensitive.
- Returns:
- Timestamp
See also
TimestampA class representing a single point in time.
PeriodRepresents a span of time with a fixed frequency.
PeriodIndex.to_timestampConvert a PeriodIndex to a DatetimeIndex.
Examples
>>> period = pd.Period('2023-1-1', freq='D') >>> timestamp = period.to_timestamp() >>> timestamp Timestamp('2023-01-01 00:00:00')
A
freqcoarser than daily gives the last day of the period:>>> pd.Period("2023-01", freq="M").to_timestamp("M") Timestamp('2023-01-31 00:00:00')