Pandas TimeStamp to Time Zone
Pandas TimeStamp to Time Zone
Pandas TimeStamp to Time Zone
- Pandas에서 Timestamp를 시간으로 바꾸는 경우, UTC+0 기준의 datetime이 설정됨
- 이렇게 바뀐 시간을 특정 time zone으로 바꾸고 싶다면, 다음과 같이 하면 됨
- timestamp를 datetime으로 변경
- datetime을
tz_localize
를 통해 UTC 시간으로 변경 tz_convert
를 통해 특정 timezone으로 변경
import pandas as pd
df = pd.DataFrame({"some_timestamp" : [160000000]})
df["date_time"] = pd.to_datetime(df["some_timestamp"], unit="ms")
df["converted_date_time"] = df["date_time"].dt.tz_localize("UTC").dt.tz_convert("Asia/Seoul")