OperationalError 1241:操作数应包含 1 列

问题描述

代码

import pandas as pd
df = pd.DataFrame(list(inverted_index.items()),columns = ['words','docids']) 
from pandas.io import sql
from sqlalchemy import create_engine
engine = create_engine("MysqL+pyMysqL://{user}:{pw}@localhost/{db}"
                       .format(user="root",pw="shreshre",db="nltk"))
df.to_sql(con=engine,name='documents',if_exists='replace')

输出

image of my error page and code output

这里我想将字典类型的倒排索引转换为数据帧并将其写入 MysqL。但我收到一个错误

OperationalError: (pyMysqL.err.OperationalError) (1241,'Operand should contain 1 column(s)')
[sql: INSERT INTO documents (`index`,words,docids) VALUES (%(index)s,%(words)s,%(docids)s)]
[parameters: ({'index': 0,'words': 'bank','docids': {0,1,2,3,4,17,18,19,20,21,22,23,25,26,27,28,37,38,39,40,41,43,44,45,46,48,52,53,54,55,56,59,60,62,64,66,67,68,69 ... (1314 characters truncated) ...  719,720,721,722,724,726,728,733,734,735,736,737,739,740,743,746,748,752,753,755,756,757,758,759,762,765,766,767,768,772}},{'index': 1,'words': 'defin',354,612,773,76,84}},{'index': 2,'words': 'establish',161,391,328,330,718,719,245,217,411,156}},{'index': 3,'words': 'custodi',405}},{'index': 4,'words': ',',8,14,24,30,31,49,51,63,65,69,70,72,73,74,78,79,80,81 ... (1428 characters truncated) ...  705,706,708,710,711,712,716,729,730,732,741,745,749,769,771,773}},{'index': 5,'words': 'loan',512,517,519,538,29,33,34,557,558,47,559,564,574,578,580,616,621,113,114,115,116,117,123,124,127,128,129,... (75 characters truncated) ...  711,200,219,227,228,234,235,241,309,310,340,343,346,349,365,368,380,383,384,385,386,440,447,448,451,453,474}},{'index': 6,'words': 'exchang',416,290,357,425,10,302,430,405,376,415}},{'index': 7,'words': 'issu',419,676,390,397,272,274,306,700,350}}  ... displaying 10 of 1969 total bound parameter sets ...  {'index': 1967,'words': '86','docids': {774}},{'index': 1968,'words': 'separ','docids': {774}})]

我无法理解在 Stackoverflow 上发布的关于类似错误existing solution。有人请帮帮我。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...