小编Sed*_*edi的帖子

将 pandas 中的时间转换为 UTC

我有多个 csv 文件,我已将 DateTime 设置为索引。

df6.set_index("gmtime", inplace=True)
#correct the underscores in old datetime format
df6.index = [" ".join( str(val).split("_")) for val in df6.index]
df6.index = pd.to_datetime(df6.index)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

时间设置为 GMT,但我认为当我为树莓派设置时钟时,它已被保存为 BST(英国夏令时)。我想把时间向后拨一小时。当我使用

df6.tz_convert(pytz.timezone('utc'))
Run Code Online (Sandbox Code Playgroud)

它给了我以下错误,因为它假设时间是正确的。

无法转换 tz-naive 时间戳,请使用 tz_localize 进行本地化

如何将时间改为一小时?

python datetime timestamp utc pandas

3
推荐指数
1
解决办法
7866
查看次数

标签 统计

datetime ×1

pandas ×1

python ×1

timestamp ×1

utc ×1