From c826a50dd592a442812035cd0bb945af09e59e9e Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Fri, 8 Apr 2022 18:30:01 -0500 Subject: [PATCH] Backport PR #46697: DOC: indicate that `month_name` and `day_name` also applies to Series --- pandas/core/arrays/datetimes.py | 38 +++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 6843e4f7eeb58..9d07a5862f11f 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -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 ---------- @@ -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'], @@ -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 ---------- @@ -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'],