简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM