有一个数据帧
它包含列数据框日期,键入对象。示例2019-01-01
我想给每个日期加上这个值‘T07:00:00+0000’,所以我想要的输出是2019-01-01T07:00:00+0000。你知道吗
我试过了
df.date + 'T07:00:00+0000', as the type of the column object
但是有个错误
TypeError: unsupported operand type(s) for +: 'datetime.date' and 'str'
好吧,如果是datetime,我们转换成字符串:
df.date.dt.strftime('%Y-%m-%d')
出现了这个错误:
AttributeError: Can only use .dt accessor with datetimelike values
为什么会这样?你知道吗
如果要使用^{} 第一次将} ,则可以将date对象转换为strings for first solution和for next:
date
对象转换为datetime
s和^{错误原因1:
对于将字符串添加到dates/datetimes,需要将其转换为字符串。你知道吗
错误2的原因:
Pandas仍然不能很好地支持
python date
,因此必须转换为datetimes。你知道吗相关问题 更多 >
编程相关推荐