Skip to content

Backport PR #46697 on branch 1.4.x (DOC: indicate that month_name and day_name also applies to Series) #46710

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
Changes from all 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
38 changes: 32 additions & 6 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,8 @@ def to_perioddelta(self, freq) -> TimedeltaArray:

def month_name(self, locale=None):
"""
Return the month names of the DateTimeIndex with specified locale.
Return the month names of the :class:`~pandas.Series` or
:class:`~pandas.DatetimeIndex` with specified locale.

Parameters
----------
Expand All @@ -1227,11 +1228,23 @@ def month_name(self, locale=None):

Returns
-------
Index
Index of month names.
Series or Index
Series or Index of month names.

Examples
--------
>>> s = pd.Series(pd.date_range(start='2018-01', freq='M', periods=3))
>>> s
0 2018-01-31
1 2018-02-28
2 2018-03-31
dtype: datetime64[ns]
>>> s.dt.month_name()
0 January
1 February
2 March
dtype: object

>>> idx = pd.date_range(start='2018-01', freq='M', periods=3)
>>> idx
DatetimeIndex(['2018-01-31', '2018-02-28', '2018-03-31'],
Expand All @@ -1247,7 +1260,8 @@ def month_name(self, locale=None):

def day_name(self, locale=None):
"""
Return the day names of the DateTimeIndex with specified locale.
Return the day names of the :class:`~pandas.Series` or
:class:`~pandas.DatetimeIndex` with specified locale.

Parameters
----------
Expand All @@ -1257,11 +1271,23 @@ def day_name(self, locale=None):

Returns
-------
Index
Index of day names.
Series or Index
Series or Index of day names.

Examples
--------
>>> s = pd.Series(pd.date_range(start='2018-01-01', freq='D', periods=3))
>>> s
0 2018-01-01
1 2018-01-02
2 2018-01-03
dtype: datetime64[ns]
>>> s.dt.day_name()
0 Monday
1 Tuesday
2 Wednesday
dtype: object

>>> idx = pd.date_range(start='2018-01-01', freq='D', periods=3)
>>> idx
DatetimeIndex(['2018-01-01', '2018-01-02', '2018-01-03'],
Expand Down