更新后的pandas

时间:2018-06-01 21:27:06

标签: python pandas sqlalchemy

我最近将pandas从.20更新到.23,现在一个将pandas DataFrame插入sql(MS SQL Server)的脚本失败了。框架与以往一样(使用pandas read_sql_table从sql读取,然后回写,仅作为测试以确保工作正常)。我没有更改任何驱动程序,例如odbc,我测试了一些在更新之前为我工作的驱动程序。失败后,我更新了sqlalchemy,但这没有帮助。

我收到此错误:

(pyodbc.ProgrammingError) ('The SQL contains 6039 parameter markers, but 137111 parameters were supplied', 'HY000')   [SQL: 'INSERT INTO dbo.test_python_drop_write_append (various column names here) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?, ?,

实际的数据帧值更远,但我没有在这里包含它们。  问号很奇怪,我无法解释。当我打印数据帧的头部时,它看起来很好,正如我所说,它是完全相同的数据帧,pandas之前已成功读取并重写到此测试脚本中的sql。我甚至不知道参数标记是什么,我不是要明确指定与它们相关的任何内容。

编写代码就是这样,它使用的是成功读取数据的相同sqlcon对象:

dataf.to_sql(name=tablename, con=sqlcon, schema=schemaname, index=False, if_exists='replace')

我希望编辑可能会让我更加关注,而且我还有更多信息。我试过通过sql炼金术代码无济于事。我试图弄清楚如何创建“insert(columns)values()”语句。这不起作用,但我注意到所有的值看起来像这样(?,?,?,?,...?,?),但是所有的实际值都作为参数传递。所以,sql语句如下所示:

     [SQL: 'INSERT INTO [dbname].[schemaname].[tablename] ([var1], [var2], [var3], [var4], [var5], [var6]) VALUES (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?),
(?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?)'] [parameters: (actualdata1, actualdata2, etc.)]

每行数据的实际数据不以()分隔。无论如何,任何有关如何解决这个问题的帮助将不胜感激。大熊猫的一些变化从0.20变为0.23使这种情况发生。我的数据有一些列名称作为数字,有些列完全填充了pandas None。

0 个答案:

没有答案