推荐学习书目
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
wxiao333
V2EX  ›  Python

当需要数据聚合查询的时候,你们是选择用数据库的聚合,还是数据库查出来使用 pandas 聚合?

  •  
  •   wxiao333 · May 18, 2024 · 2770 views
    This topic created in 749 days ago, the information mentioned may be changed or developed.
    最近在写一个基于 MongoDB 的项目(第一次用,之前主要用 Mysql ),涉及到聚合查询的时候,搜了一下发现聚合查询需要用 pipeline, 因为项目的数据有点复杂,写聚合 pipeline 特别别扭,也容易出错,然后突然想起来我用的既然是 python ,岂不是可以先从数据库把数据查出来,再用 pandas 做聚合?试了一下,各种复杂聚合果然很快就实现了,有一种思维打开的感觉。
    效率方面没有实际验证过,但感觉上数据库原生聚合 效率会比 查出来再 pandas 要高一点的,不过太复杂的聚合可能数据库不一定能完全实现,这时候用 pandas 就方便多了。
    你会怎么选呢?
    2 replies    2024-05-18 18:57:33 +08:00
    ruanimal
        1
    ruanimal  
       May 18, 2024
    看数据量啊
    LeeReamond
        2
    LeeReamond  
       May 18, 2024
    数据库屎在完整性和一致性约束,实现本身还是高效的。pandas 的屎就是纯屎了,慢而已。你对性能有需求自然不会选择这种方案,你在考虑这种方案说明你对性能没需求,那用啥不行?如果不能决定我建议抽个签
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1589 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 00:00 · PVG 08:00 · LAX 17:00 · JFK 20:00
    ♥ Do have faith in what you're doing.