我有一個帶有 UTC 格式的“日期”列的資料框。
Date
2021-10-14T06:57:00.000 0000
2021-09-05T08:30:00.000 0000
2021-10-20T04:34:00.000 0000
2021-10-19T21:49:00.000 0000
2021-09-30T20:53:00.000 0000
試過這個但沒有用;
df['Date'] = df['Date'].substr(replace(to_iso8601(from_iso8601_timestamp(Date) AT TIME ZONE 'Australia/Melbourne'), 'T', ' '), 1, 16) Date_local
我無法將 UTC 時間轉換為本地時區(澳大利亞/墨爾本)。
任何幫助將不勝感激。
uj5u.com熱心網友回復:
使用熊貓功能;pd.to_datetime然后是tz_convert。
# input strings to datetime data type:
df['Date'] = pd.to_datetime(df['Date'])
# UTC is already set (aware datetime); just convert:
df['Date'] = df['Date'].dt.tz_convert('Australia/Melbourne')
df['Date']
Out[2]:
0 2021-10-14 17:57:00 11:00
1 2021-09-05 18:30:00 10:00
2 2021-10-20 15:34:00 11:00
3 2021-10-20 08:49:00 11:00
4 2021-10-01 06:53:00 10:00
Name: Date, dtype: datetime64[ns, Australia/Melbourne]
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/355819.html
下一篇:java.time.format.DateTimeParseException:無法在索引2處決議文本“103545”
