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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP