【发布时间】:2019-05-05 07:10:59
【问题描述】:
我有一个名为 aero 的数据集 我正在尝试将给定列中的字符串日期更改为日期时间 这是字符串的格式:
In: aero['Date Local'].unique()
Out: array(['2000-01-01', '2000-01-02', '2000-01-03', ..., '2016-03-04',
'2016-03-05', '2016-03-06'], dtype=object)
如果我错了,请纠正我,但这看起来像是一个可变的字符串列表 这是我尝试过的代码:
for stuff in aero['Date Local']:
aero['Date Local'][stuff] = datetime.datetime.strptime(stuff, "%Y-%m-%d")
产生了错误:
ValueError: ['2' '0' '0' '0' '-' '0' '1' '-' '0' '1'] not contained in the index
我试图弄清楚这意味着什么,但无济于事。有人可以帮我将这些字符串转换为日期时间吗?
【问题讨论】:
标签: python string python-3.x numpy datetime