将函数应用于数据框列(datetime.date)

时间:2015-11-20 03:38:14

标签: python pandas

我有以下代码

 def func (datas):

                giorno=calendar.day_name[int(datas.day)]
                mese=calendar.month_name[int(datas.month)]
                day = getattr(result,'beta')
                day=getattr(day,'%s'%(giorno))
                month= getattr(result,'beta')
                month=getattr(month,'%s'%(mese))
                intercept=result.beta.intercept
                d = datetime.date(2015, 1, 1)
                holiday_map = dict(cal.holidays(d.year))  
                holiday_=holiday_map.get(d, '?')
                holiday= getattr(result,'beta')
                holiday=getattr(holiday,holiday_)
                return int(intercept)+int(month)+int(day)+int(holiday)

我正在尝试在数据集列“Days”(datetime.date类型)上应用此公式:

df_reg['regression']=df_reg['days'].map(lambda datas: data(datas))

但是我收到以下错误:

C:\Anaconda3\lib\calendar.py in __getitem__(self, i)
     73 
     74     def __getitem__(self, i):
---> 75         funcs = self._days[i]
     76         if isinstance(i, slice):
     77             return [f(self.format) for f in funcs]

IndexError: list index out of range

1 个答案:

答案 0 :(得分:0)

检查第一行中datas.day的值。它超出了范围。

有效值为[0,1,2,3,4,5,6]