简体   繁体   English

pandas dataframe.to_sql 关闭自动时区偏移

[英]pandas dataframe.to_sql turn off automatic timezone offset

Pandas DataFrame.to_sql automatically adds FixedOffsetTimezone to dataframe. Pandas DataFrame.to_sql 自动将 FixedOffsetTimezone 添加到数据帧。 My initial dataframe index doesnt have timezone:我的初始数据帧索引没有时区: 在此处输入图片说明

However, when I try to save dataframe and retrieve values, returned index has timezone -4:但是,当我尝试保存数据帧并检索值时,返回的索引的时区为 -4:

在此处输入图片说明

在此处输入图片说明

Does anyone know how to turn it off?有谁知道怎么关掉? Pandas documentation doesnt mention it dataframe.to_sql Pandas 文档没有提到它dataframe.to_sql

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

where con=SQL Alchemy connection其中 con=SQL Alchemy 连接

Database=Postgres with pgAdmin 4 Database=Postgres with pgAdmin 4

I found the solution: the problem was indeed in the postgres settings.我找到了解决方案:问题确实出在 postgres 设置中。 Database timezone was set to -4.数据库时区设置为 -4。 Here's the sql to set timezone to 0这是将时区设置为 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';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 熊猫DataFrame.to_sql和nan值 - pandas DataFrame.to_sql and nan values pandas dataframe.to_sql 在写入 MariaDB 时抛出错误 - pandas dataframe.to_sql throws error when writing to MariaDB pandas DataFrame.to_sql()函数if_exists参数不起作用 - pandas DataFrame.to_sql() function if_exists parameter not working Attempting to insert date string into SQL table with pandas dataframe.to_sql function, but it reformats the string - Attempting to insert date string into SQL table with pandas dataframe.to_sql function, but it reformats the string Pandas DataFrame.to_sql()错误 - 不是在字符串格式化期间转换的所有参数 - Pandas DataFrame.to_sql() error - not all arguments converted during string formatting 如何在 dataframe.to_sql 中指定 Int? - how to specify Int in dataframe.to_sql? 如何回滚 SQLALCHEMY 中 python 中的 dataframe.to_sql? - How to rollback dataframe.to_sql in python in SQLALCHEMY? Python熊猫0.14.0。 使用dataframe.to_sql时时间戳格式错误 - Python Pandas 0.14.0. Error with timestamp format when using dataframe.to_sql MySQL 在多线程环境下使用DataFrame.to_sql时出现死锁 - MySQL Deadlock when using DataFrame.to_sql in multithreaded environment 为什么我的 dataframe.to_sql 会引发 DBAPI 错误? - Why is my dataframe.to_sql throwing a DBAPI error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM