我想把从SAS到Python的工作流程转换,迄今为止已经相当成功,除了一件非常重要的事情。 我无法弄清楚如何将 Pandas 数据帧上传到我们公司的 Netezza,以供稍后查询使用。这实际上非常重要,因为我们有许多数据集需要上传并用于查询。
我有以下 Pandas 数据帧:
[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?
pyodbc.cursor.execute()
命令之内吗?或者我可以以某种方式与 Pandas 一起使用它?