雪花convert_timezone在大熊猫中不起作用

发布于 2025-02-07 01:05:18 字数 494 浏览 2 评论 0原文

convert_timezone在雪花控制台中对我有用:

select convert_timezone('America/Los_Angeles', '2022-05-25T14:27:30Z'::TIMESTAMP_TZ)

给予:

2022-05-25T07:27:27:30-07:00,

但在熊猫中不起作用pread sql:

pd.read_sql("select convert_timezone('America/Los_Angeles', '2022-05-25T14:27:30Z'::TIMESTAMP_TZ)", engine).values

giss:gress:

array([[timestamp('2022-05-25)('2022-05-25 21:' 27:30+0000',tz ='utc')]],dtype = object)

如何解决此问题?

convert_timezone works for me in the snowflake console:

select convert_timezone('America/Los_Angeles', '2022-05-25T14:27:30Z'::TIMESTAMP_TZ)

gives:

2022-05-25T07:27:30-07:00

but it does not work in pandas read sql:

pd.read_sql("select convert_timezone('America/Los_Angeles', '2022-05-25T14:27:30Z'::TIMESTAMP_TZ)", engine).values

gives:

array([[Timestamp('2022-05-25 21:27:30+0000', tz='UTC')]], dtype=object)

any ideas how to fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

予囚 2025-02-14 01:05:18

当大熊猫从雪花上接收时间戳值时,它会将其转换为datetime64 [ns]。感觉就像在您的情况下,大熊猫将时间戳转换为UTC。

我建议使用一系列方法对数据框中的值进行转换,例如,

.tz_localize("UTC").tz_convert("America/Los_Angeles"))

您可以通过进入UI -&gt来确保Snowflake生成预期的时间戳;历史记录并检查Python连接器生成的查询。在查询结果部分中,您将能够看到实际的时间戳返回给Pandas,很可能是预期的。因此,应在大熊猫上对其进行调整。

When pandas receives TIMESTAMPs values from Snowflake it converts them to datetime64[ns]. It feels like in your case pandas converts the timestamp to UTC.

I suggest applying a conversion on the values in the dataframe using a series of methods like

.tz_localize("UTC").tz_convert("America/Los_Angeles"))

You can make sure that Snowflake generates the expected timestamp by going to the UI -> History and checking your query generated by Python Connector. In the query result section, you will be able to see the actual timestamp returned to pandas, highly likely it will be the expected one. Therefore, it should be adjusted on pandas.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文