在python中将数据集中的日期转换为yyyy-mm-dd
我已经写了我的代码,除了日期之外,我有很好的结果。我的日期格式为“2020年1月12日”,我想将其转换为yyyy-mm-dd。有人能帮我纠正我所犯的错误吗。这是我的密码:在python中将数据集中的日期转换为yyyy-mm-dd,python,pandas,datetime,Python,Pandas,Datetime,我已经写了我的代码,除了日期之外,我有很好的结果。我的日期格式为“2020年1月12日”,我想将其转换为yyyy-mm-dd。有人能帮我纠正我所犯的错误吗。这是我的密码: Date = item['reviews'] for d in Date: names.append(name) date = d['date'].strftime("%Y-%m-%d") dates.append(date) print('&g
Date = item['reviews']
for d in Date:
names.append(name)
date = d['date'].strftime("%Y-%m-%d")
dates.append(date)
print('>>>>>>>>>>>>>>>>>> ', date)
输出为:
Traceback (most recent call last):
File "C:/Users/User/Pycharmresult.py", line 95, in <module>
date = d['date'].strftime("%Y-%m-%d")
AttributeError: 'str' object has no attribute 'strftime'
回溯(最近一次呼叫最后一次):
文件“C:/Users/User/Pycharmresult.py”,第95行,在
日期=d['date'].strftime(“%Y-%m-%d”)
AttributeError:“str”对象没有属性“strftime”
我需要执行哪些操作来更正错误?我认为您必须首先将列转换为
datetime
pd.to_datetime(d['date']).strftime("%Y-%m-%d")
我认为您必须首先将列转换为
datetime
pd.to_datetime(d['date']).strftime("%Y-%m-%d")