在使用to_sql写入数据库时,出现报错
sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1241, 'Operand should contain 1 column(s)')
是由于dataframe中存在值为列表的情况,需要将列表转为字符串
df.loc[:, ‘xxxx’] = df_main[‘xxxx’].astype(str)
在使用to_sql向数据库写入DataFrame时,若遇到'Operand should contain 1 column(s)'错误,通常是因为DataFrame中某列的数据类型为列表。解决方法是将该列的所有列表元素转换为字符串。
在使用to_sql写入数据库时,出现报错
sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1241, 'Operand should contain 1 column(s)')
是由于dataframe中存在值为列表的情况,需要将列表转为字符串
df.loc[:, ‘xxxx’] = df_main[‘xxxx’].astype(str)

被折叠的 条评论
为什么被折叠?