Not sure if this is feasible or if there is support for it.
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DatetimeIndex.dayofweek.html gives the day of the week with Monday=0, Sunday=6.
For my application I would like Sunday=0 and Saturday=6.
I wonder if there could be a startday argument to dayofweek
? e.g. dayoftheweek(startday='Sunday')
with dayoftheweek(startday='Monday')
being the default.
I used a workaround in my case:
df['weekday'] = df.index.dayofweek
df_weekday_mean = df.groupby('weekday').mean()
df_weekday_mean = df_weekday_mean.iloc[np.arange(-1, len(df_weekday_mean)-1)].reset_index()
Output of pd.show_versions()
Comment From: chris-b1
I think it's a reasonable idea, but would be a breaking API change to turn the property into callable, so a bit painful.
You could shift the days yourself more directly with addition/modulo
df = pd.DataFrame({'date': pd.date_range('2014-01-01', periods=10)})
df['day_name'] = df.date.dt.day_name()
df['dayofweek-MON'] = df.date.dt.dayofweek
df['dayofweek-SUN'] = (df.date.dt.dayofweek + 1) % 7
df['dayofweek-SAT'] = (df.date.dt.dayofweek + 2) % 7
In [26]: df
Out[26]:
date day_name dayofweek-MON dayofweek-SUN dayofweek-SAT
0 2014-01-01 Wednesday 2 3 4
1 2014-01-02 Thursday 3 4 5
2 2014-01-03 Friday 4 5 6
3 2014-01-04 Saturday 5 6 0
4 2014-01-05 Sunday 6 0 1
5 2014-01-06 Monday 0 1 2
6 2014-01-07 Tuesday 1 2 3
7 2014-01-08 Wednesday 2 3 4
8 2014-01-09 Thursday 3 4 5
Comment From: mroeschke
Thanks for the suggestion, but since there hasn't been much community or core dev interest in years going to close for now. Happy to reopen if there's renewed interest