pandas.to_datetime错误 [英] pandas.to_datetime ERROR

查看:184
本文介绍了pandas.to_datetime错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个pandas数据框,我想将time列转换为datetime格式.

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

时间

2013年5月30日06:00:41 -0600

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'

推荐答案

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

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()

这篇关于pandas.to_datetime错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆