熊猫,Psycopg2,时区抵消

时间:2016-07-13 01:33:11

标签: python postgresql datetime pandas timezone-offset

我使用psycopg2连接到postgres数据库,然后在pandas中操作数据并使用matplotlib绘制结果。

从postgres数据库我可以获得时区偏移小时,例如-7-6等 我想使用tzoffset字段将时间戳转换为适当的时区。我以为我可以将它转换为timedelta但没有这样的运气。有帮助吗?

this question似乎使用csv导入熊猫似乎有类似的东西,所以我无法想象它太难了但我无法弄明白。任何帮助将不胜感激。

conn = pg.connect(
user = dbinfo.username,
host = dbinfo.hostname,
database = dbinfo.path[1:],
password = dbinfo.password,
)

sql = """

SELECT
some_TIMESTAMP as starttime,
tzoffset AS tzoffset (*COMES OUT AS `-7`*)
FROM
    table"""
###Connection to the database
df = pd.read_sql_query(sql, con=conn)

0 个答案:

没有答案