Skip to content

Commit ef49a8e

Browse files
authored
Example for pandas.DataFrame.to_period docs (#43967)
1 parent 3976bba commit ef49a8e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pandas/core/frame.py

+22
Original file line numberDiff line numberDiff line change
@@ -10503,6 +10503,28 @@ def to_period(
1050310503
Returns
1050410504
-------
1050510505
DataFrame with PeriodIndex
10506+
10507+
Examples
10508+
--------
10509+
>>> idx = pd.to_datetime(
10510+
... [
10511+
... "2001-03-31 00:00:00",
10512+
... "2002-05-31 00:00:00",
10513+
... "2003-08-31 00:00:00",
10514+
... ]
10515+
... )
10516+
10517+
>>> idx
10518+
DatetimeIndex(['2001-03-31', '2002-05-31', '2003-08-31'],
10519+
dtype='datetime64[ns]', freq=None)
10520+
10521+
>>> idx.to_period("M")
10522+
PeriodIndex(['2001-03', '2002-05', '2003-08'], dtype='period[M]')
10523+
10524+
For the yearly frequency
10525+
10526+
>>> idx.to_period("Y")
10527+
PeriodIndex(['2001', '2002', '2003'], dtype='period[A-DEC]')
1050610528
"""
1050710529
new_obj = self.copy(deep=copy)
1050810530

0 commit comments

Comments
 (0)