在SQL Join中使用Pandas Dataframe
- 论坛
- 在SQL Join中使用Pandas Dataframe
8 浏览
在SQL Join中使用Pandas Dataframe
我正在尝试在Postgres数据库中将DataFrame的内容与外部表进行SQL连接。
DataFrame的样子是这样的:
>>> df name author count 0 a b 10 1 c d 5 2 e f 2
我需要将其与一个Postgres表连接起来,它的样子是这样的:
TABLE: blog title author url a b w.com b b x.com e g y.com
我尝试的方法是这样的,但是这个查询的语法似乎不正确:
>>> sql_join = r"""select b.*, frame.* from ({0}) frame join blog b on frame.name = b.title where frame.owner = b.owner order by frame.count desc limit 30;""".format(df) >>> res = pd.read_sql(sql_join, connection)
我不确定如何在SQL查询中使用DataFrame中的值。
有人能给我指点一下吗?谢谢!
编辑:根据我的用例,由于内存和性能限制,我无法将blog表转换为DataFrame。