Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.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-循环表中的行并传递SQL参数_Python_Sql_Parameters - Fatal编程技术网

Python-循环表中的行并传递SQL参数

Python-循环表中的行并传递SQL参数,python,sql,parameters,Python,Sql,Parameters,我试图在循环中从数据帧传递一行。我想使用dataframe中的每个元素作为SQL调用的一组参数 df = [1,2,3]#this would actually be a table with several rows import as a dataframe for row in df.itertuples: sql = 'Select * from table where a = ? and b = ? and c = ?' ds = p

我试图在循环中从数据帧传递一行。我想使用dataframe中的每个元素作为SQL调用的一组参数

     df = [1,2,3]#this would actually be a table with several rows import as a dataframe
     for row in df.itertuples:
        sql = 'Select * from table where a = ? and b = ? and c = ?'
        ds = pd.read_sql(sql, db_conn, params={row[1], row[2], row[3]})
        clf = LogisticRegression(ds)

这是我认为可行的基本框架。我的想法是,我有一个表,其中包含创建逻辑回归模型所需的所有组合。我需要基于多个列的较大数据集的子集。我试图减少一次输入整个数据集的次数。

你的问题不清楚。是否要插入或检索数据?您是否正在寻找一种方法来参数化a、b和c?可能有许多有用的选项。基本上,您可以使用sql中的limit来限制行,但您的问题对我来说仍然不清楚。“我已经创建了一个表,其中的列包含我希望作为sql参数传递的值,用于检索sql表的子集。假设我的SQL表有一百万行。传递时的参数会将其分解为我想要建模的分组。我不希望只发生任何分块,我希望数据的特定视图。那么什么对您不起作用呢?当运行与上述类似的逻辑并尝试只打印“ds”时,我得到数据库错误:“DatabaseError:Execution failed on sql”,并显示我的查询结束,并在我的查询结束时传递参数,我看到一堆unicode…\x00\x00\n\x00\x00\x00\x00。。。。。。我知道没有实际的代码很难进行诊断,所以我会以“循环表并将该表的条目传递给SQL查询的最佳方式是什么”的形式给出答案。我试图避免在按照我想要的方式将表切片之前将整个表都拉进去…内存问题。在这种情况下,我想知道您的代码是如何到达sql执行之前的
itertuples
而不是
itertuples()