Skip to content

DOC: update pandas.DatetimeIndex.to_period docstring(Nairobi) #20131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 12, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,30 @@ def to_pydatetime(self):

def to_period(self, freq=None):
"""
Cast to PeriodIndex at a particular frequency
Cast to PeriodIndex at a particular frequency.

Converts DatetimeIndex to periodIndex.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra space, can you capitalize PeriodIndex


Parameters
----------
freq : string or pandas offset object, optional
One of pandas date offset string or corresponding objects.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you include a link to the table of alias. Something like

:ref:`offset aliases <timeseries.offset_aliases>`


Returns
-------
period: period[D]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

period : DatetimeIndex

(need the space between the two).


Examples
--------
>>> df = pd.DataFrame({"y": [1,2,3]},
... index=pd.to_datetime(["2000-03-31 00:00:00",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make 'index' right below the {.

... "2000-05-31 00:00:00",
... "2000-08-31 00:00:00"]))
>>> df.index = df.index.to_period("M")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And maybe just assign index = pd.to_datetime([...]), no df.

Then index.to_period("M") and show the output.


See also
--------
Index: base pandas index type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove Index. Add pandas.PeriodIndex pandas.DatetimeIndex.to_pydatetime

"""
from pandas.core.indexes.period import PeriodIndex

Expand Down