我有一系列 datetime64[ns] 对象。
我想提取日期和分钟 (HH:MM) 部分。到目前为止,我正在使用下面的代码,但速度很慢。我怎样才能更有效地做到这一点?
>>> type(df['EXECUTION_TIMESTAMP'])
Out[1]: pandas.core.series.Series
>>> df['EXECUTION_TIMESTAMP']
Out[1]:
0 2012-12-13 16:46:37
1 2012-12-13 16:46:42
2 2012-12-13 16:46:47
...
68 2010-09-07 15:21:38
69 2013-07-21 21:40:14
70 2010-07-21 22:44:46
Name: EXECUTION_TIMESTAMP, Length: 769552, dtype: datetime64[ns]
# Get the DateTimes Only
ets = pd.Series(df['EXECUTION_TIMESTAMP'])
print('Converting times')
dt_min = []
dd = []
for x in ets:
dt_min.append(pd.datetime(2000,1,1,x.hour,x.minute))
dd.append(pd.datetime(x.year,x.month,x.day))