Machine learning
[데이터 전처리]. 날짜 데이터 전처리
Acdong
2021. 2. 9. 10:41
728x90
![]() |
![]() |
우리는 위처럼 시간데이터를 DateTime 형태로 받아 들이게 되는 데 이것을 문자열로 나눠서 정제하는 방법도 있지만
쉽게 파생변수로 만들어주는 방법이 있다.
tt['Date'] = pd.to_datetime(tt['Date'])
tt['Wday'] = tt['Date'].dt.day_name()
tt['yyyymm'] = tt['Date'].dt.strftime('%Y%m')
tt['yyyy'] = tt['Date'].dt.strftime('%Y')
tt['mm'] = tt['Date'].dt.strftime('%m')
tt['dd'] = tt['Date'].dt.strftime('%d')
tt['hh'] = tt['Date'].dt.strftime('%H')
이렇게 해주면 알아서 분리 된다.
끝
반응형