Skip to content

DOC: update the Period.dayofweek attribute docstring #20280

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
31 changes: 31 additions & 0 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,37 @@ cdef class _Period(object):

@property
def dayofweek(self):
"""
Return the day of the week.

This attribute returns the day of the week on which the particular
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm not mistaken, this will return the day of the week on which the particular starting date for the given period occurs. I think this is important to mention, because at first I was confused thinking "how a period of one month can have a day of the week?".

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we have this discussion in another PR as well (https://github.com/pandas-dev/pandas/pull/20277/files#r173651389). Only, it is not necessarily the starting date, it depends on the freq.

Copy link
Member

Choose a reason for hiding this comment

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

Issue is here: #20324.

date for the given period occurs depending on the frequency with
Monday=0, Sunday=6.

Returns
-------
Int
Range from 0 to 6 (included).

See also
--------
Period.dayofyear : Return the day of the year.
Period.daysinmonth : Return the number of days in that month.

Examples
--------
>>> period1 = pd.Period('2012-1-1 19:00', freq='H')
>>> period1
Period('2012-01-01 19:00', 'H')
>>> period1.dayofweek
6

>>> period2 = pd.Period('2013-1-9 11:00', freq='H')
>>> period2
Period('2013-01-09 11:00', 'H')
>>> period2.dayofweek
2
"""
base, mult = get_freq_code(self.freq)
return pweekday(self.ordinal, base)

Expand Down