无法使用熊猫在 mysql 数据库中添加分解数据



我想在我的数据库中插入使用熊猫爆炸的数据,但我得到一个错误,有人可以帮助

我的代码

tactic_theme = pandas.read_csv(link, usecols=(0, 7))
tactic_theme.columns = ['code_tac', 'code_th']
tactic_theme['code_th'] = tactic_theme.code_th.str.split(" ")
tactic_theme.explode('code_th')
tactic_theme.to_sql('tactic_themes', con = engine, if_exists='replace',index=False,chunksize = 1000)

误差

sqlalchemy.exc。操作错误:(pymysql. error .OperationalError) (1241,'操作数应该包含1列')[SQL: INSERT INTO tactic_themes .(code_tac, code_th) VALUES (%(code_tac)s, %(code_th)s)][参数:({"code_tac":"0000 d"、"code_th":["优势","最后阶段","短")},{"code_tac":"0009 b","code_th":[‘优势’,‘middlegame’,"短")},{"code_tac":"000 vc,"code_th":["破碎","结局","长"、"pawnEndgame ']},{"code_tac":"000年佐薇","code_th":["结局","伴侣"、"mateIn2"、"短")},{"code_tac":"000 ay","code_th":["优势","大师","middlegame","短")},{"code_tac":"000高频","code_th":[‘伴侣’,‘mateIn2’,‘middlegame’,"短")},{"code_tac":"000年,","code_th":"粉碎","middlegame","短")},{"code_tac":000罗,"code_th":"粉碎","最后阶段","叉","短"]}…显示1000个总绑定参数集中的10个…{"code_tac":"01哈克"、"code_th":["优势","开放","短")},{"code_tac":"01 hv2"、"code_th":[‘伴侣’,‘mateIn1’,‘middlegame’,‘oneMove]}))

我刚刚看到了错误,在tactic_theme.explode('code_th')行我应该写

tactic_theme = tactic_theme.explode('code_th')

最新更新