Closed antoinecarme closed 4 years ago
Check if this can capture religious holidays (Easter , Holy Week etc)
Avoid WeekOfMonth approximation, more intuitive and takes care of first day of month being Tuesday etc (increasing ordinal values are also guaranteed).
def get_week_of_month(self, series):
lFirstDayOfMonth = series - pd.to_timedelta(series.dt.day - 1, unit='D')
return series.dt.weekofyear - lFirstDayOfMonth.dt.weekofyear + 1
Closing
For business daily data the signal may be better analyzed by crossing dayOfWeek and week index in month.
This can be made by dividing the work month in weeks and analyzing WeekOfMonth.
WeekOfMonth = dayOfMonth // 7
(This is only an approximation, not to be confused with WeekOfYear, which is already analyzed by PyAF)
An important derivative is DayOfNthWeekOfMonth, a crossing of DayOfWeek and WeekOfMonth
DayOfNthWeekOfMonth = WeekOfMonth * 7 + DayOfWeek
This pattern captures concepts like 'first Monday of month' , 'last Tuesday' , 'third Friday' etc.