- API reference
- Series
- pandas.Serie...
pandas.Series.to_timestamp#
- Series.to_timestamp(freq=None,how='start',copy=None)[source]#
Cast to DatetimeIndex of Timestamps, atbeginning of period.
- Parameters:
- freqstr, default frequency of PeriodIndex
Desired frequency.
- how{‘s’, ‘e’, ‘start’, ‘end’}
Convention for converting period to timestamp; start of periodvs. end.
- copybool, default True
Whether or not to return a copy.
Note
Thecopy keyword will change behavior in pandas 3.0.Copy-on-Writewill be enabled by default, which means that all methods with acopy keyword will use a lazy copy mechanism to defer the copy andignore thecopy keyword. Thecopy keyword will be removed in afuture version of pandas.
You can already get the future behavior and improvements throughenabling copy on write
pd.options.mode.copy_on_write=True
- Returns:
- Series with DatetimeIndex
Examples
>>>idx=pd.PeriodIndex(['2023','2024','2025'],freq='Y')>>>s1=pd.Series([1,2,3],index=idx)>>>s12023 12024 22025 3Freq: Y-DEC, dtype: int64
The resulting frequency of the Timestamps isYearBegin
>>>s1=s1.to_timestamp()>>>s12023-01-01 12024-01-01 22025-01-01 3Freq: YS-JAN, dtype: int64
Usingfreq which is the offset that the Timestamps will have
>>>s2=pd.Series([1,2,3],index=idx)>>>s2=s2.to_timestamp(freq='M')>>>s22023-01-31 12024-01-31 22025-01-31 3Freq: YE-JAN, dtype: int64
On this page