Python Pandas——將時間戳轉換為其他時區
使用timestamp.tz_convert()將時間戳轉換為其他時區。將時區設定為引數。首先,匯入所需的庫——
import pandas as pd
在 Pandas 中建立時間戳物件。我們還設定了時區
timestamp = pd.Timestamp('2021-10-14T15:12:34.261811624', tz='US/Eastern')
轉換時間戳時區
timestamp.tz_convert('Australia/Brisbane'))
例項
以下是程式碼
import pandas as pd # set the timestamp object in Pandas # we have also set the timezone timestamp = pd.Timestamp('2021-10-14T15:12:34.261811624', tz='US/Eastern') # display the Timestamp print("Timestamp...\n", timestamp) # convert timezone print("\nConvert the Timestamp timezone...\n", timestamp.tz_convert('Australia/Brisbane'))
輸出
這將生成以下程式碼
Timestamp... 2021-10-14 15:12:34.261811624-04:00 Convert the Timestamp timezone... 2021-10-15 05:12:34.261811624+10:00
廣告