import pandas as pd
import psycopg2
conn=psycopg2.connect(database="****", user="postgres", password="***", port="5432")
with conn:
cur=conn.cursor()
cur.execute("select * from public.20160407_1")
rows = cur.fetchall()
t=pd.DataFrame(rows)
import psycopg2
conn=psycopg2.connect(database="****", user="postgres", password="***", port="5432")
with conn:
cur=conn.cursor()
cur.execute("select * from public.20160407_1")
rows = cur.fetchall()
t=pd.DataFrame(rows)
本文介绍如何利用Python中的pandas和psycopg2库连接PostgreSQL数据库,并从中获取指定表格的数据。通过示例代码展示了建立数据库连接、执行SQL查询及将结果转换为DataFrame的过程。
595

被折叠的 条评论
为什么被折叠?



