在pandas數據框中創建IsHoliday功能

2024-10-02 08:28:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在我的网站上创建一个iSoliday功能pd.数据帧,以datetime作为索引,基于包含一年中的假日的csv文件。由于对pandas没有什么经验,我可以通过比较两个数据帧的值来想到一种迭代方法 更具体地说:

for i in range(0,len(Holidays)-1):
 for j in range(0,len(df)-1):
    if (Holidays.loc[i,'month']==df.loc[j,'month'] and 
      Holidays.loc[i,'day']==df.loc[j,'day'] ):
        df.loc[j,'Isholiday']=1

    else: 
        df.loc[j,'Isholiday']=0

我的问题是,如何以避免所有加工时间的方式实现这一点?你知道吗


Tags: 数据in功能dfforlen网站holidays

热门问题