当前位置: 首页 > article >正文

python实现数据库两个表之间的更新操作(模糊匹配)示例

from pymongo import MongoClient
import pandas as pd


# 连接到MongoDB(这里假设MongoDB运行在本地默认端口上)
mgclient = MongoClient('localhost', 27017)

# 选择数据库(如果你没有指定数据库,MongoDB会使用默认的'test'数据库)
db = mgclient['test']  # 替换'your_database_name'为你的数据库名
test1_collection=db["test1"].find({})
test1_list=list(test1_collection)
test2_collection=db["test2"].find({})
test2_list=list(test2_collection)

# 这种方式只适合插入存在的数据。
for document1 in test1_list:
    document1.pop("_id")
    document1["codename"]=document1["code"]
    # document1["codename"] = document1["code"]
    for document2 in test2_list:
        # dataframe包含关系不是很好merge
        if document1["code"]==document2["code"] and document1["code"].startswith(document2["code"]):
            document1["codename"]=document2["name"]
            print(document1)
            # 如果只用写入能够匹配上的,在这里insert
            # db["test3"].insert_one(document1)
    db["test3"].insert_one(document1)










http://www.kler.cn/news/368733.html

相关文章:

  • CSS中为特定的元素设置背景图片(Top1,Top1,Top3)
  • C++ | Leetcode C++题解之第514题自由之路
  • 服务器数据恢复—EXT3文件系统下邮件数据被误删的数据恢复案例
  • 提示工程(Prompt Engineering)指南(进阶篇)
  • ELK日志收集
  • Linux - 动静态库
  • Django-cookie,session
  • 工作中用到的 Linux 总结(持续更新中...)
  • Word 删除空白页:亲测有效的方法
  • 【JavaEE】【多线程】线程池
  • 理解BERT的词向量及其初始化参数的一致性
  • Redis 集群 总结
  • 单片机中的BootLoader(使用汇编指令进行跳转)
  • Linux系列-yum软件安装包
  • 一次调整prompt的过程
  • docker常用命令整理
  • RabbitMQ几个核心概念
  • 通过页面添加国际化数据,实现vue的国际化
  • J2学习打卡
  • 分账系统适用于那些商家?
  • Spring Boot植物健康系统:绿色科技的创新
  • TensorFlow面试整理-TensorFlow 和 PyTorch 的区别是什么?
  • 论文阅读(二十五):PVTv2: Improved Baselines with Pyramid Vision Transformer
  • SASS转换成CSS步骤
  • 宝塔如何部署Django项目(前后端分离篇)
  • Three.js 使用着色器 实现跳动的心