如何将 Pandas 数据框写入 Vertica? [英] How do I write a pandas dataframe to Vertica?

查看:84
本文介绍了如何将 Pandas 数据框写入 Vertica?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望写入 Vertica 的 Pandas 数据框中有一些数据集.我已经使用 vertica_python 库创建了我的表.将数据框写入 Vertica 的最佳方式是什么?

I have some data set in a pandas data frame that I wish to write to Vertica. I've already created my table using the vertica_python library. What is the best way to write my data frame to Vertica?

推荐答案

通常在连接到 Vertica 时,您可以使用 Postgresql 作为替代,因为 Vertica 的某些部分最初基于 Postgresql.

Often when connecting to Vertica, you can use Postgresql as a stand-in since certain parts of Vertica were originally based on Postgresql.

from sqlalchemy import create_engine
engine = create_engine('postgresql://user:pass@host:5433/MYDB')
df.to_sql('table_name', engine)

如果这不起作用,您可以尝试使用 vertica-sqlalchemy 包.

If this doesn't work you could try out the vertica-sqlalchemy package.

此外,根据创建的 SQL(如果 ODBC 驱动程序将 INSERT 转换为 COPY),这可能会非常慢.如果您发现它正在对数据库进行大量单独的插入,您可能希望切换到 COPY 方法,在该方法中创建字符串和 COPY FROM STDIN 来制作速度更快.

Also, depending on the SQL created (and if the ODBC driver converts INSERT to a COPY) this might be very slow. If you find that it is doing lots of individual inserts on the database, you'll probably want to switch to a COPY method where you create strings and COPY FROM STDIN to make it faster.

这篇关于如何将 Pandas 数据框写入 Vertica?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆