-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Period with YYYY-UU (week of the year) #48947
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
Comments
take |
take |
This is a part of #48000 . I've done an overview of the state of Pandas in that issue conversation. It includes lots of examples on how weeks and other periods are handled now. It's convoluted and definitely worth a look. |
Hi @joooeey I like the explanations you provided in #48000. However, I would like to give my suggestion another try and I also modify my feature suggestion. I believe that reopening the ticket and exploring the potential benefits of this feature could bring significant value to pandas users, especially those who work extensively with week of year periods. Problem statement: Solution:
The X-axis has datetime format, not week of year format Thanks, Matt |
I agree with the others that we don't need an extra method to retrieve a year-week string from a Period as you proposed in #49355 as there are easy ways to achieve this and if we go down this route the combinations get endless (methods for year and week separately already exist and there's also However, as a user I'd appreciate it if the other direction (reading) was possible. In my opinion support for ISO 8601 is a worthwhile goal. I.e. I'm not so excited about esoteric use cases such as |
Thanks Joooeey for your comment. Since this feature may not be widely used (I still see many use cases in different industries), I will come up with another method. I have the following comments about the issues with some of the week of year handling approaches: |
Closing as covered by #48000 |
Feature Type
Adding new functionality to pandas
Changing existing functionality in pandas
Removing existing functionality in pandas
Problem Description
I am working with a widely used index for many industries which has week of year as index. Here is an example:
"2020-01"
"2020-02"
...
"2020-52"
"2021-01"
...
"2021-52"
dtype: str
Right now there is no feature to present this kind of Period and I have to use it like this:
2019-12-29
2020-01-05
...
2020-12-20
2020-12-27
...
2021-12-19
dtype: period[7D]
What I suggest is a new period, say YW, which is formatted as YYYY-UU as below:
2020-01
2020-02
...
2020-52
2021-01
...
2021-52
dtype: period[YW]
Feature Description
def to_period(freq="YW"):
""""Gets a single index as "2021-52"
returns Period (2021-52, YW)
""""
Alternative Solutions
def convert_weekstr_to_period(idx: str) -> pd.Period:
"""Converts single string week to Period.
The weeks start from 00 and the offset of one week will be applied.
Args:
idx (str): str of format yyyy-ww, e.g., 2022-51
def pd_series_weekstr_to_period(dsw: pd.Series) -> pd.Series:
"""Converts a Pandas Series string week to Period.
Additional Context
The current format has a day attached that is redundant.
The text was updated successfully, but these errors were encountered: