2
일련의 datetime64 [ns] 개체가 있습니다.Python, datetime64의 시리즈를 날짜와 분으로 변환
날짜 및 분 (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))
튜플 목록으로하지 표시
도움 주셔서 감사합니다. 마지막 zip 명령은 튜플 목록을 분 및 초로 지정합니다. 대신 datetime의 데이터 프레임을 반환하는 방법이 있습니까? – Ginger
최종 목표는 무엇인지 확실하지 않지만 도움이되는지 알려주세요. – Jeff