■ to_datetime 함수를 사용해 DataFrame 객체의 특정 컬럼을 날짜 타입으로 변경하는 방법을 보여준다.
▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import pandas as pd airQualityNO2DataFrame = pd.read_csv("air_quality_no2_long.csv") renameAirQualityNO2DataFrame = airQualityNO2DataFrame.rename(columns = {"date.utc" : "datetime"}) print(renameAirQualityNO2DataFrame["datetime"].dtype) # object renameAirQualityNO2DataFrame["datetime"] = pd.to_datetime(renameAirQualityNO2DataFrame["datetime"]) print(renameAirQualityNO2DataFrame["datetime"].dtype) # datetime64[ns, UTC] |
▶ requirements.txt
1 2 3 4 5 6 7 8 |
numpy==2.1.2 pandas==2.2.3 python-dateutil==2.9.0.post0 pytz==2024.2 six==1.16.0 tzdata==2024.2 |
※ pip install pandas 명령을 실행했다.