본문 바로가기

Python3

[python3] 데이터프레임에 있는 초단위 삭제하기

해결

#데이터 형태
df['start_date_time'] = ["2016-05-19 08:25:00","2016-05-19 16:00:00","2016-05-20 07:45:00","2016-05-24 12:50:00","2016-05-25 23:00:00","2016-05-26 19:45:00"]

#초단위 삭제(Timezone이 제거 될 수 있음)
df['start_date_time'] = df['start_date_time'].values.astype('<M8[m]')

#결과
print (df)
      start_date_time
0 2016-05-19 08:25:00
1 2016-05-19 16:00:00

 

설명

astype을 이용 '<M8[m]'으로 초단위를 제거한단다.

 

출처

https://stackoverflow.com/questions/43387467/how-to-remove-seconds-from-datetime