DateTime 열 다루기
pandas는 기본적으로 datetime 열을 object 데이터 타입으로 불러옵니다. 텍스트 형태의 날짜는 시계열 분석에 큰 도움이 되지 않으므로, 해당 열을 datetime 데이터 타입으로 변환할 수 있어야 해요. 이 타입을 사용하면 pandas의 날짜를 더 유연하게 다루고, 유용한 특성을 쉽게 추출할 수 있습니다.
이번에는 Apple 주가 데이터셋이 apple로 로드되어 있습니다.
이 연습은 강의의 일부입니다
Python으로 배우는 이상치 탐지
연습 안내
apple의Date열을datetime열로 변환하세요.- 요일을 추출해
day_of_week라는 새 열에 저장하세요. - 월(숫자)을 추출해
month라는 새 열에 저장하세요. - 일(한 달 중 날짜)을 추출해
day_of_month라는 새 열에 저장하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Convert the Date column to DateTime
apple['Date'] = ____
# Create a column for the day of the week
apple['day_of_week'] = ____
# Create a column for the month
apple['month'] = ____
# Create a column for the day of the month
apple['day_of_month'] = ____
print(apple[['day_of_week', 'month', 'day_of_month']])