pandas.to_datetime ERROR

蓝咒 提交于 2019-12-11 01:34:02

问题


I have a pandas dataframe and I want to convert the time column to datetime format.

Time

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

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

But it always gives the following error.What is the problem with the code? :(

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'

回答1:


The to_datetime function was introduced in 0.8.0, so you'll have to upgrade your pandas to use it.
Ideally to the latest stable version.




回答2:


Use set_index to set the time column as the index, and then convert the Index to DateTimeIndex:

df = df.set_index('Time')

df.index = df.index.to_datetime()


来源:https://stackoverflow.com/questions/16910795/pandas-to-datetime-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!