J.Guo
J.Guo

Reputation: 37

how can I make a holiday indicator in my dataframe

DataOrigin['isholiday'] = DataOrigin['arrival'].apply(lambda x: 1 if x=='2016-06-10'or'2016-06-09'or '2016-06-11'else 0)

enter image description here

Please click on the image first, above is my code My description is including in the picture, aprreciated!

Upvotes: 0

Views: 114

Answers (1)

Alexander
Alexander

Reputation: 109528

You can use isin to check if the values are in a given subset of data.

DataOrigin['isholiday'] = DataOrigin['arrival'].isin(['2016-06-10', '2016-06-09', '2016-06-11'])

If you really want ones and zeroes instead of True/False, just append .astype(int) to the statement above. True/False should evaluate the same as 1/0, so it is really down to preference or your specific use case.

Upvotes: 2

Related Questions