【发布时间】:2015-03-23 20:33:20
【问题描述】:
我有一个如下所示的 Pandas DataFrame
ReviewID ID Type TimeReviewed
205 76032930 51936827 ReportID 2015-01-15 00:05:27.513000
232 76032930 51936854 ReportID 2015-01-15 00:06:46.703000
233 76032930 51936855 ReportID 2015-01-15 00:06:56.707000
413 76032930 51937035 ReportID 2015-01-15 00:14:24.957000
565 76032930 51937188 ReportID 2015-01-15 00:23:07.220000
>>> type(df)
<class 'pandas.core.frame.DataFrame'>
TimeReviewed 是一个系列类型
>>> type(df.TimeReviewed)
<class 'pandas.core.series.Series'>
我在下面尝试过,但它仍然没有改变系列类型
import pandas as pd
review = pd.to_datetime(pd.Series(df.TimeReviewed))
>>> type(review)
<class 'pandas.core.series.Series'>
如何将 df.TimeReviewed 更改为 DateTime 类型并分别提取年、月、日、小时、分钟、秒? 我对python有点陌生,感谢您的帮助。
【问题讨论】:
标签: python datetime pandas dataframe