【问题标题】:pandas dataframe.to_sql turn off automatic timezone offsetpandas dataframe.to_sql 关闭自动时区偏移
【发布时间】:2019-11-03 20:52:24
【问题描述】:

Pandas DataFrame.to_sql 自动将 FixedOffsetTimezone 添加到数据帧。我的初始数据帧索引没有时区:

但是,当我尝试保存数据框并检索值时,返回的索引具有时区 -4:

有人知道怎么关掉吗? Pandas 文档没有提到它dataframe.to_sql

ats.all.to_sql("ats_all", con, if_exists="replace")

其中 con=SQL Alchemy 连接

Database=带有 pgAdmin 4 的 Postgres

【问题讨论】:

    标签: python pandas postgresql sqlalchemy


    【解决方案1】:

    我找到了解决方案:问题确实出在 postgres 设置中。数据库时区设置为 -4。这是将时区设置为 0 的 sql

    --check current timezone setting
    SELECT current_setting('TIMEZONE');
    
    --need to restart database for the change to kick in
    ALTER DATABASE postgres SET timezone TO 'GMT';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-12
      • 1970-01-01
      • 1970-01-01
      • 2012-08-14
      • 1970-01-01
      • 2015-06-08
      • 2022-10-19
      • 1970-01-01
      相关资源
      最近更新 更多