pandas.to_datetime 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16910795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
pandas.to_datetime ERROR
提问by Nilani Algiriyage
I have a pandas dataframe and I want to convert the time column to datetime format.
我有一个Pandas数据框,我想将时间列转换为日期时间格式。
Time
时间
30/May/2013 06:00:41 -0600
2013 年 5 月 30 日 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'
回答by waitingkuo
Use set_index to set the time column as the index, and then convert the Indexto DateTimeIndex:
使用 set_index 将时间列设置为索引,然后将其转换Index为DateTimeIndex:
df = df.set_index('Time')
df.index = df.index.to_datetime()
回答by Andy Hayden
The to_datetimefunction was introduced in 0.8.0, so you'll have to upgrade your pandas to use it.
Ideally to the latest stable version.

