[英]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. 您可以使用
isin
检查值是否在给定的数据子集中。
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. 如果您真正想要的是1和0而不是True / False,则只需将
.astype(int)
附加到上面的语句中。 True/False should evaluate the same as 1/0, so it is really down to preference or your specific use case. 正确/错误的评估结果应与1/0相同,因此实际上取决于偏好或您的特定用例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.