1.原始数据:
holiday.dtypes
Day object
Date object
Holiday object
dtype: object
2.对时间进行操作:给日期加上年
holiday['Date'] = holiday['Date'].apply(lambda x: x + ' 2016')
holiday.head()
datetime.strptime(holiday.loc[0,'Date'], '%B %d %Y')
结果:
datetime.datetime(2016, 1, 1, 0, 0)
datetime.strptime(holiday.loc[0,'Date'], '%B %d %Y').date()
结果: datetime.date(2016, 1, 1)
holidays = [datetime.strptime(holiday.loc[i,'Date'], '%B %d %Y').date() for i in range(len(holiday))]
print(holidays)
结果: