使用 LST 时区的时间序列数据,没有夏令时。如何将其转换为 PST8PDT?
我正在 Pandas 中使用 NOAA 每小时气象数据,该数据以当地标准时间记录(不考虑夏令时)。如何将其转换为采用夏令时的 LST?
到目前为止,我已尝试向 tz naive 日期时间数据添加 8 小时偏移,本地化为 UTC,然后转换回 PST8PDT,但这不起作用。
import pandas as pd
import datetime as dt
from datetime import timedelta
Date_time = pd.to_datetime(df.DATE) + pd.Timedelta('8 hours')
Date_time = Date_time.dt.tz_localize('UTC')
Date_time = Date_time.dt.tz_convert('PST8PDT')
编辑:感谢您的所有帮助!我使用固定偏移量(UTC-8)进行本地化,但是当我转换为“America/Los_Angeles”或“PST8PDT”时,似乎所有日期时间都偏离了-8或-7小时,除非我误解了日期时间约定。
这是我转换为“美国”后的日期时间数据/Los_Angeles”时区。
所见,它适用夏令时,但是我对所有日期时间都显示“-08:00”或“-07:00”这一事实感到困惑。这是否意味着从每个显示的日期时间中减去 8 或 7 小时?或者我误解了这一点?
不管怎样,好消息是我发现如果我只是将数据保留在具有固定偏移量的 UTC 时区中,我就可以毫无问题地使用它。
I am working in Pandas with NOAA hourly meteorological data, which is recorded in Local Standard Time (without regard for daylight savings time). How can I convert this to LST with Daylight Savings?
So far I have tried adding an 8 hour offset to the tz naive datetime data, localizing to UTC, then converting back to PST8PDT, but that did not work.
import pandas as pd
import datetime as dt
from datetime import timedelta
Date_time = pd.to_datetime(df.DATE) + pd.Timedelta('8 hours')
Date_time = Date_time.dt.tz_localize('UTC')
Date_time = Date_time.dt.tz_convert('PST8PDT')
EDIT: Thank you for all the help! I localized with the fixed offset (UTC-8), but when I convert to 'America/Los_Angeles' or 'PST8PDT' it seems like all the datetimes are off by -8 or -7 hours, unless I am misunderstanding the datetime conventions.
To illustrate the problem:
Here's the raw time data
Here's the datetime data after I localize to UTC with fixed offset
And here's the datetime data after I convert to "America/Los_Angeles" time zone.
As you can see, it applies Daylight Savings Time, however I am confused by the fact that all the datetimes say "-08:00" or "-07:00". Does that mean that 8 or 7 hours is being subtracted from each displayed datetime? Or am I misinterpreting that?
Either way, the good news is I found that if I just leave the data in UTC timezone with the fixed offset, I am able to work with it without any issues.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论