使用pandas.DataFrame.to_sql時報錯Operand should contain 1 column(s)

在使用to_sql寫入數據庫時,出現報錯

sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1241, 'Operand should contain 1 column(s)')

是由於dataframe中存在值爲列表的情況,需要將列表轉爲字符串
df.loc[:, ‘xxxx’] = df_main[‘xxxx’].astype(str)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章