コード例 #1
0
 def clean_electricity(self):
     import datetime
     #Get holiday dates in France using the library called workalendar
     from workalendar.europe import France
     cal = France()
     #Convert dates to DateTime format
     self.df['Date'] = pd.to_datetime(self.df['Date'], format='%d/%m/%Y')
     #Create the DayTypes mentioned in the article (except DayType 8)
     #/!\ We chose an arbitrary order to create the day types, since they are not separated sets
     #Add normal weekdays (DayType 1)
     self.df['Day_type'] = self.df['Date'].apply(lambda u: (u.date(), 1))
     #Add Mondays (DayType 0)
     self.df['Day_type'] = self.df['Day_type'].apply(
         lambda x: (x[0], 0) if x[0].weekday() == 0 else x)
     #Add Fridays (DayType 2)
     self.df['Day_type'] = self.df['Day_type'].apply(
         lambda x: (x[0], 2) if x[0].weekday() == 4 else x)
     #Add Saturdays (DayType 3)
     self.df['Day_type'] = self.df['Day_type'].apply(
         lambda x: (x[0], 3) if x[0].weekday() == 5 else x)
     #Add Sundays (DayType 4)
     self.df['Day_type'] = self.df['Day_type'].apply(
         lambda x: (x[0], 4) if x[0].weekday() == 6 else x)
     #Add Bank holidays (DayType 6)
     self.df['Day_type'] = self.df['Day_type'].apply(
         lambda x: (x[0], 6) if cal.is_holiday(x[0]) == True else x)
     #Add Before Bank holidays (DayType 5)
     self.df['Day_type'] = self.df['Day_type'].apply(
         lambda x: (x[0], 5) if cal.is_holiday(x[0] + datetime.timedelta(
             days=1)) == True else x)
     #Add After Bank holidays (DayType 7)
     self.df['Day_type'] = self.df['Day_type'].apply(
         lambda x: (x[0], 7) if cal.is_holiday(x[0] - datetime.timedelta(
             days=1)) == True else x)
     self.df['Day_type'] = self.df['Day_type'].apply(lambda x: x[1])
     self.df['Date'] = self.df['Date'].apply(lambda u: u.date())
コード例 #2
0
def is_holiday_fr(date_of_interest):
    cal = France()
    result = cal.is_holiday(date_of_interest) # this will return a boolean True/False value
    # cast to integer
    result = int(result)
    return result