Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.Series.to_period#

Series.to_period(freq=None,copy=None)[source]#

Convert Series from DatetimeIndex to PeriodIndex.

Parameters:
freqstr, default None

Frequency associated with the PeriodIndex.

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 writepd.options.mode.copy_on_write=True

Returns:
Series

Series with index converted to PeriodIndex.

Examples

>>>idx=pd.DatetimeIndex(['2023','2024','2025'])>>>s=pd.Series([1,2,3],index=idx)>>>s=s.to_period()>>>s2023    12024    22025    3Freq: Y-DEC, dtype: int64

Viewing the index

>>>s.indexPeriodIndex(['2023', '2024', '2025'], dtype='period[Y-DEC]')

[8]ページ先頭

©2009-2025 Movatter.jp