如何从pandas dataframe中提取日期/年/月?

我正在尝试从pandas dataframe的'date‘列中提取年份/日期/月份信息。下面是我的示例代码:

from datetime import datetime
def date_split(calendar):
  for row in calendar: 
    new_calendar={}
    listdate=datetime.strptime(row['date'],'%Y-%M-%D')

我还没有完成完整的代码,但当我测试运行这一部分时,我总是得到这样的错误:

----> 7         listdate=datetime.strptime(row['date'],'%Y-%M-%D')
TypeError: string indices must be integers

有谁知道吗?

顺便说一句,这是我使用的数据帧(calendar_data):

?

?

转载请注明出处:http://www.haofang-home.com/article/20230521/1438590.html