1

I am trying to add holidays column for France in a Dataframe by using workalendar package but it gives me an error of

Series' object has no attribute 'weekday'

Below is my code;

from workalendar.europe import France
df1 = pd.read_csv('C:\Users\ABC.csv')
df1['Date'] = pd.to_datetime(df1['Date'], format= '%d/%m/%Y %H:%M:%S')
df1['Date1'] = df1.Date.dt.date
dr = df1['Date1']
cal = France()
df1['Holiday'] = cal.is_working_day(df1['Date1'])
df1.head()

The original data in the file looks like this;

Date                Value
17/10/2012 19:00:00 0
17/10/2012 20:00:00 0.1
17/10/2012 21:00:00 0
17/10/2012 22:00:00 0
17/10/2012 23:00:00 0
18/10/2012 00:00:00 0
18/10/2012 01:00:00 0
18/10/2012 02:00:00 0
18/10/2012 03:00:00 0.1
18/10/2012 04:00:00 0
18/10/2012 05:00:00 0
18/10/2012 06:00:00 0
18/10/2012 07:00:00 0
18/10/2012 08:00:00 0.2
18/10/2012 09:00:00 0.5

`

Muhammad
  • 305
  • 2
  • 6
  • 20

1 Answers1

0

Try this.

df1['Holiday'] = df1.Date.apply(lambda x: cal.is_working_day(pd.to_pydatetime(x)))

You have to convert the object type to datetime.

BTW, I thought that working_day would might not be Holiday...

Converting between datetime, Timestamp and datetime64

Community
  • 1
  • 1
adamist521
  • 33
  • 5
  • Thanks but it outputs 2016-03-25 and 2016-03-28 as True (means they are working days), which they are not as these are Good Friday and Easter Monday. I get correct results while checking `cal.is_working_day(date(2016,3,28))` – Muhammad Jun 08 '16 at 08:22
  • Edited answer. Data format should have been python's datetime. (`to_pydatetime`) – adamist521 Jun 15 '16 at 00:47
  • http://stackoverflow.com/questions/22825349/converting-between-datetime-and-pandas-timestamp-objects could help – adamist521 Jun 15 '16 at 00:54
  • it keeps giving me error `'module' object has no attribute 'to_pydatetime'`. Any idea? I think my pandas is up to date. Any ideas? – Muhammad Jun 20 '16 at 16:09
  • Which version of pandas are you using? `to_datetime` should also work. – adamist521 Jun 22 '16 at 00:33