Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.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 如何将数据框插入到包含列表的列的表中_Python_Pandas_Dataframe_Pandas To Sql - Fatal编程技术网

Python 如何将数据框插入到包含列表的列的表中

Python 如何将数据框插入到包含列表的列的表中,python,pandas,dataframe,pandas-to-sql,Python,Pandas,Dataframe,Pandas To Sql,我有一个pandas数据框,其中一列包含列表格式tield(即[2ndchance]) 我想按原样将其插入数据库,但得到一个错误 我正在执行以下句子: df_playbyplay.to_sql('playbyplay', con=engine, if_exists='replace', index=False) 它失败时会出现以下错误: ProgrammingError:(mysql.connector.errors.ProgrammingError)处理pyformat参数失败;Python

我有一个pandas数据框,其中一列包含列表格式tield(即[2ndchance])

我想按原样将其插入数据库,但得到一个错误

我正在执行以下句子:

df_playbyplay.to_sql('playbyplay', con=engine, if_exists='replace', index=False)
它失败时会出现以下错误:

ProgrammingError:(mysql.connector.errors.ProgrammingError)处理pyformat参数失败;Python“列表”无法转换为MySQL类型[SQL:“插入到playbyplay中”


我想按原样将其添加到表中,如果不可能,只想将其从我的数据帧中删除,但无论我执行什么,似乎总是将其识别为列表,而原来它只是一个字符串。

变量列表每个单元格都不遵循SQL安全规则,这种类型的插入可能会导致SQL注入攻击

我推荐的

df['list of columns']=df['list of columns'].str.join(', ')

然后我们插入数据库

感谢您的回答,事实并非如此,我正在废弃一个web并获取一个json,json的一列包含这种格式[2ndchance,pointsinthepaint],因为我想在使用该命令时将其插入数据库中。要使用sql,我对该特定字段有问题。因此需要的解决方案之一就是删除[]