【发布时间】:2015-11-10 06:37:37
【问题描述】:
我希望将我的工作流程从 SAS 更改为 Python,到目前为止,我取得了相当大的成功,除了一件非常大的事情。我不知道如何将 Pandas DataFrames 上传到我公司的 Netezza 以供以后查询使用。这实际上非常重要,因为我们有许多上传和用于查询的数据集。
我有以下熊猫数据框:
[In ] df
[Out]
col1 col2 col3
0 1 2 3
1 4 5 6
2 7 8 9
我想通过 ODBC 连接将此 DataFrame 上传到我的 Netezza 盒子。连接已经建立如下:
import pyodbc
conn = pyodbc.connect("Driver=NetezzaSQL;Server=...;")
我已将此连接与 Pandas read_sql 结合使用来提取数据并将其存储在 DataFrame 中。但是,我还没有弄清楚如何提取数据。在 SAS 中,我会执行以下操作:
proc sql _method;
connect to netezza as net_dw
(auth domain info goes here...)
execute( create temporary table my_table
( col1 int,
col2 int,
col3 int ) distribute on (col1) by net_dw)
insert into temp.my_table
select col1, col2, col3 from work.my_table;
quit;
我使用 Pandas 尝试了以下操作:
t = pd.read_sql('''create temporary table test1 (col1 int, col2 int, col3 int); insert into temp.test1 select * from df''', conn)
但得到了TypeError: 'NoneType' object is not iterable。
是否可以使用 pyodbc 和 Pandas 将临时表上传到 Netezza?
【问题讨论】:
标签: python sql pandas odbc netezza