def seconds_between(self, end_date, start_date): # indicate time of working hours biz_open_time = time(8, 0, 0) biz_close_time = time(17, 0, 0) holiday_list = pyholidays.CZ() unit = 'sec' try: difference = businessDuration(startdate=start_date, enddate=end_date, starttime=biz_open_time, endtime=biz_close_time, holidaylist=holiday_list, unit=unit) return(difference) except Exception as e: print(e) return('Error in Date')
def get_days_of_week(self, start="2018-01-01", end="2018-12-31"): cz_holidays = holidays.CZ() date_list = pd.date_range(start=start, end=end).tolist() output_list = [] for d in date_list: weekday = int(d.strftime('%w')) for _ in range(0, 24): output_list.append([ int(weekday == 1), int(weekday == 2), int(weekday == 3), int(weekday == 4), int(weekday == 5), int(weekday == 6), int(weekday == 0), int(d in cz_holidays) ]) return output_list
def judge_local_holiday(self, df): country = df['geoNetwork_country'] date = df['visitId'].apply(lambda x: x.date()) judge_holiday = \ np.where(country.isin( ['United States','India','Canada','Germany', 'Japan','France','Mexico','Australia', 'Spain','Netherlands','Italy','Ireland', 'Sweden','Argentina','Colombia','Belgium', 'Switzerland','Czechia','Colombia','Belgium', 'New Zealand','South Africa','South Africa']),\ np.where((country=='United States')& (date.isin(holidays.US())),1, np.where((country=='India')& (date.isin(holidays.India())),1, np.where((country=='Canada')& (date.isin(holidays.CA())),1, np.where((country=='Germany')& (date.isin(holidays.DE())),1,\ np.where((country=='Japan')& (date.isin(holidays.JP())),1, np.where((country=='France')& (date.isin(holidays.FRA())),1, np.where((country=='Mexico')& (date.isin(holidays.MX())),1, np.where((country=='Australia')& (date.isin(holidays.AU())),1,\ np.where((country=='Spain')& (date.isin(holidays.ES())),1, np.where((country=='Netherlands')& (date.isin(holidays.NL())),1, np.where((country=='Italy')& (date.isin(holidays.IT())),1, np.where((country=='Ireland')& (date.isin(holidays.IE())),1,\ np.where((country=='Sweden')& (date.isin(holidays.SE())),1, np.where((country=='Argentina')& (date.isin(holidays.AR())),1, np.where((country=='Colombia')& (date.isin(holidays.CO())),1, np.where((country=='Belgium')& (date.isin(holidays.BE())),1,\ np.where((country=='Switzerland')& (date.isin(holidays.CH())),1, np.where((country=='Czechia')& (date.isin(holidays.CZ())),1, np.where((country=='Denmark')& (date.isin(holidays.DK())),1, np.where((country=='Austria')& (date.isin(holidays.AT())),1,\ np.where((country=='Hungary')& (date.isin(holidays.HU())),1, np.where((country=='Portugal')& (date.isin(holidays.PT())),1, np.where((country=='Norway')& (date.isin(holidays.NO())),1, np.where((country=='Portugal')& (date.isin(holidays.PT())),1,\ np.where((country=='New Zealand')& (date.isin(holidays.NZ())),1, np.where((country=='South Africa')& (date.isin(holidays.ZA())),1, np.where((country=='South Africa')& (date.isin(holidays.ZA())),1,\ 0))))))))))))))))))))))))))),np.nan).astype(int) return judge_holiday
country_holidays = { "CA": holidays.CA(), "CO": holidays.CO(), "MX": holidays.MX(), "US": holidays.US(), "NZ": holidays.NZ(), "AU": holidays.AU(), "DE": holidays.DE(), "AT": holidays.AT(), "DK": holidays.DK(), "UK": holidays.UK(), "IE": holidays.IE(), "ES": holidays.ES(), "CZ": holidays.CZ(), "SK": holidays.SK(), "PL": holidays.PL(), "PT": holidays.PT(), "NL": holidays.NL(), "NO": holidays.NO(), "IT": holidays.IT(), "SE": holidays.SE(), "JP": holidays.JP(), "BE": holidays.BE(), "ZA": holidays.ZA(), "SI": holidays.SI(), "FI": holidays.FI(), "CH": holidays.CH() }
def setUp(self): self.holidays = holidays.CZ()