pandas.to_datetime错误

时间:2013-06-04 05:59:52

标签: python pandas ipython-notebook

我有一个pandas数据帧,我想将时间列转换为datetime格式。

时间

30 / May / 2013 06:00:41 -0600

import pandas as pd
df.index = pd.to_datetime(df.pop('Time'))

但它总是会出现以下错误。代码有什么问题? :(

AttributeError                            Traceback (most recent call last)
<ipython-input-124-9219cf10d027> in <module>()
----> 1 df.index = pd.to_datetime(df.pop('Time'))

AttributeError: 'module' object has no attribute 'to_datetime'

2 个答案:

答案 0 :(得分:0)

使用set_index将时间列设置为索引,然后将Index转换为DateTimeIndex

df = df.set_index('Time')

df.index = df.index.to_datetime()

答案 1 :(得分:0)

to_datetime函数为introduced in 0.8.0,因此您必须升级您的pandas才能使用它。
理想情况下是latest stable version

相关问题