我是Pandas的新手你可以帮助我将对象类型转换为datetime。
之前
index timestamp
0 ISODate(2016-10-02T07:37:22.584+05:00)
1 ISODate(2016-10-02T07:37:22.589+05:00)
2 ISODate(2016-10-02T07:37:22.590+05:00)
3 ISODate(2016-10-02T07:37:40.668+05:00)
通过以下命令替换stings:
df['timestamp'].replace(['ISODate','"'],'',regex=True,inplace = True)
现在df['timestamp']
是。
index timestamp
0 (2016-10-02T07:37:22.584+05:00)
1 (2016-10-02T07:37:22.589+05:00)
2 (2016-10-02T07:37:22.590+05:00)
3 (2016-10-02T07:37:40.668+05:00)
帮我修改object_type数据到日期和时间。任何帮助都可以得到赞赏。
答案 0 :(得分:1)
您可以尝试:
df['timestamp'] = df['timestamp'].str[1:-1]
df['timestamp'] = pd.to_datetime(df['timestamp'] )