9
我如何串的大熊猫索引转换为datetime格式蟒蛇大熊猫转换指数为datetime
我的数据框“东风”就是这样
value
2015-09-25 00:46 71.925000
2015-09-25 00:47 71.625000
2015-09-25 00:48 71.333333
2015-09-25 00:49 64.571429
2015-09-25 00:50 72.285714
但该指数是字符串类型,但我需要datetime格式,因为我得到的错误
'Index' object has no attribute 'hour'
使用
df['A'] = df.index.hour
时
'df.index.to_datetime()'或'df.index = pandas.to_datetime(df.index)'(前者现在已经过时)。 – AChampion
类型(df.index [1])仍然返回'str' –
上面的数据转换为'datetime'没有问题 - type(df.index [1])== pandas.tslib.Timestamp'。数据框的其余部分是否有错误的数据? – AChampion