【发布时间】:2022-01-02 17:06:40
【问题描述】:
我尝试使用 SQLAlchemy 和 pandas 的 to_sql 将包含 JSON 列的表保存到 MySQL 中挣扎了很长时间。
我收到了这个错误
sqlalchemy.exc.ProgrammingError: (mysql.connector.errors.ProgrammingError) Failed processing pyformat-parameters; Python 'list' cannot be converted to a MySQL type
当尝试按照以下标准方式进行操作时。我有一个 pandas 数据框 (df),其中有两列包含 JSON('videos' 和 'newsitems')。
import sqlalchemy
connection = sqlalchemy.create_engine(f"mysql+mysqlconnector://{user}:{pw}@{host}/{db}")
table_name = 'TABLENAME'
df.to_sql(table_name,
connection,
if_exists='append',
index=False)
【问题讨论】:
标签: python mysql pandas sqlalchemy