我试图转换
使用Pandas'将'11/09/2011 11:33:00 PM +0000'
(对象)转换为日期时间变量pd.to_datetime()
:
df['Datetime'] = pd.to_datetime(df['Datetime'],format = '%d/%m/%Y %I:%M:%S %p', utc=True)
然后收到错误:
"重复列&可能减少维度"
有什么建议吗?
答案 0 :(得分:1)
如果+0000
已修复,您可以将其添加到格式字符串中,如:
pd.to_datetime(df['Datetime'], format='%d/%m/%Y %I:%M:%S %p +0000', utc=True)
df = pd.DataFrame([
'11/09/2011 11:33:00 PM +0000',
'11/09/2011 11:33:00 PM +0000',
'11/09/2011 11:33:00 PM +0000',
], columns=['Datetime'])
print(df)
df['Datetime'] = pd.to_datetime(
df['Datetime'], format='%d/%m/%Y %I:%M:%S %p +0000', utc=True)
print(df)
Datetime
0 11/09/2011 11:33:00 PM +0000
1 11/09/2011 11:33:00 PM +0000
2 11/09/2011 11:33:00 PM +0000
Datetime
0 2011-09-11 23:33:00+00:00
1 2011-09-11 23:33:00+00:00
2 2011-09-11 23:33:00+00:00