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
#setthetimestampobjectinPandas
#wehavealsosetthetimezone
timestamp = pd.Timestamp('2021-10-14T15:12:34.261811624', tz='US/Eastern')
#displaytheTimestamp
print("Timestamp...\n", timestamp)
#converttimezone
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
热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短