首页 > 解决方案 > 使用 pandas 数据框中的新值更新数据库中的列

问题描述

我正在尝试使用已计算并输入到 pandas 数据框中的新值来更新 oracle 数据库上的列。数据库中的表名是protein_info,我要更新的列是pct。运行代码时出现以下错误:

回溯(最后一次调用):文件“./update_nsaf.py”,第 81 行,在 df.to_sql(protein_info,engine,index=False,if_exists='replace')AttributeError:类型对象'protein_info' 没有属性'降低'

df = df[['id', 'pct']]
engine=create_engine('oracle://scott:tiger@localhost:5432/mydatabase', echo=False)
connect = engine.raw_connection()
df.to_sql(protein_info, engine, index=False,  if_exists='replace')
sql = """ 
    UPDATE protein_info
    SET protein_info.pct = pct
    FROM protein_info
    WHERE protein_info.id = id
"""
connect.execute(sql)
connect.close()

标签: python-3.xpandassqlalchemyflask-sqlalchemy

解决方案


推荐阅读