Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无需正确写入即可将数据帧与Oracle表连接的有效方法_Python_Sql_Oracle_Pandas - Fatal编程技术网

Python 无需正确写入即可将数据帧与Oracle表连接的有效方法

Python 无需正确写入即可将数据帧与Oracle表连接的有效方法,python,sql,oracle,pandas,Python,Sql,Oracle,Pandas,在Python中,使用Pandas,我有一个数据帧,我想与Oracle数据库中的表连接。 我在数据库中没有写入权限。因此,我目前: #select the column you want to use to query ID_list = data['ID'] #cut the list in chunks of 1000 to overcome Oracle limitation on SQL query chunks = [ID_list[x:x+1000] for x in range(

在Python中,使用Pandas,我有一个数据帧,我想与Oracle数据库中的表连接。
我在数据库中没有写入权限。因此,我目前:

#select the column you want to use to query
ID_list = data['ID']

#cut the list in chunks of 1000 to overcome Oracle limitation on SQL query
chunks = [ID_list[x:x+1000] for x in range(0, len(ID_list), 1000)]

#initiate connection to Oracle
cnxn = pyodbc.connect('DSN=XXX;UID=YYY;PWD=ZZZ')

#initiate an empty frame
df = pd.DataFrame()

#query each chunk of 1000 ID and append it to df
for chunk in chunks:
    sql_query = 'SELECT * FROM TABLE_X WHERE ID IN (' + ','.join(map(str, chunk)) + ')'
    df = df.append(pd.read_sql(sql_query, cnxn), ignore_index=True)
然后我会处理df,也许会把它和数据合并。 我确信它比SQL连接慢得多,但我不能上传我的数据帧


这是最有效的解决方案吗?

难道你不能让所有Oracle表都连接到DataFrame并使用pandas连接操作连接两个DataFrame吗?@arturro可能不是因为SQL查询limitations@arturro:理论上是可能的,但表的大小使其不可更改,而且比当前代码更耗时。