简体   繁体   English

如何在数据框中制作假期指标

[英]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.

相关问题 如何让 Python 识别 DataFrame 单元格中的星号? - How can I make Python recognize an asterisk in a cell of my DataFrame? 如何让我的 dataframe 识别日期? - How can I make my dataframe recognize dates? 如何在python中使指示器功能更快或更聪明? - How can I make the indicator function faster or smarter in python? 如何让熊猫知道假期? - How to make Pandas aware of holiday dates? 如何制作一个 for 循环来填充 DataFrame? - how can I make a for loop to populate a DataFrame? 我如何纠正我的错误并使数据帧成为使用 python 中的函数的文本文件 - How can i correct my error and make the dataframe a text file using functions in python 尝试将 append 添加到列表时,如何使我的 pandas DataFrame 循环更有效率 - How can I make my pandas DataFrame loop more efficient when trying to append to a list 如何按列而不是按行将我的 dataframe 变成 numpy 数组? - How can I make my dataframe into a numpy array by column rather than by row? 如何自动从 dataframe 列进行自然对数计算? - How can I make my natural logarithm calculation from dataframe columns automatic? 如何为我的 pandas Z6A8000755DF47794C55555 上的每个名称制作单独的 excel 表(在 1 个 excel 文件中) - How can I make separate excel sheets (in 1 excel file) for each Name on my pandas dataframe?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM