V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
QGabriel
V2EX  ›  Python

如何遍历 dataframe 数据插入 pymysql 里?

  •  
  •   QGabriel · 2021-11-04 11:55:30 +08:00 · 1843 次点击
    这是一个创建于 894 天前的主题,其中的信息可能已经有所发展或是发生改变。
    一个 6000 行的 dataframe,遍历每行存到 sql 里.
    之前都用 MongoDB 换了 sql 不会用了
    6 条回复    2021-11-04 17:48:10 +08:00
    imn1
        1
    imn1  
       2021-11-04 12:47:04 +08:00
    遍历 df.itertuples(index=False)
    至于写入 mysql ,还是自己看手册吧
    mmrindextt
        2
    mmrindextt  
       2021-11-04 14:05:12 +08:00
    直接映射成 orm 实体,批量 CRUD
    QGabriel
        3
    QGabriel  
    OP
       2021-11-04 14:42:34 +08:00
    @mmrindextt 谢谢
    mjawp
        4
    mjawp  
       2021-11-04 14:44:01 +08:00
    不是有个 df.to_sql 嘛
    NCZkevin
        5
    NCZkevin  
       2021-11-04 17:31:35 +08:00
    转成 list,写好 sql 语句,直接 executemany(sql,data)
    ipwx
        6
    ipwx  
       2021-11-04 17:48:10 +08:00
    executemany
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1396 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 23:52 · PVG 07:52 · LAX 16:52 · JFK 19:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.