python-3.x - 使用 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()
解决方案
推荐阅读
- php - Laravel 属于多由两个中间表?
- python - 创建一个 LSTM 网络来训练和预测多个时间序列
- mongodb - MongoDB 聚合查询将状态分组到区域中
- unit-testing - 如何使用 CodeceptJS 对 JS 函数进行单元测试
- linux - 赛普拉斯强制远程下载
- python - 无法在 VS Code 中更改 Jupyter 内核
- javascript - 嵌套 ES6 类
- c# - 分组后Linq select语句不起作用
- sql - Postgresql根据日期将单行拆分为多行
- amazon-s3 - AWS 云上用于 pyspark EMR 应用程序的 CI/CD 管道