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

用 pymysql 怎么实现取出列为特定值的最后连续行?

  •  
  •   yellowtail · Feb 15, 2021 · 2112 views
    This topic created in 2094 days ago, the information mentioned may be changed or developed.
    比如表[-20:-10]行 a 列的值是 1,[-9:-5]行 a 列值为 2,[-4:]行 a 列值为 1,每列特定值的行数都是不规则的,求教如何仅取出 a 列值为 1 的最后 5 行?
    因为涉及的数据可能比较多所以决定学着用 sql 而不是本地的 dataframe,但是网上看了一圈没有发现 sql 有类似 df.loc[df.a==df.a+1]的操作,求大佬搭救
    hannibalm
    hannibalm
    Feb 15, 2021
    1
    数据库是集合概念,不加 order by 情况下,不保证每次取 a = 1 返回的行顺序相同
    dorothyREN
    dorothyREN
    Feb 15, 2021
    2
    @hannibalm #1 加了 orderby 也不能保证吧。相同值的顺序
    hannibalm
    hannibalm
    Feb 15, 2021
    3
    @dorothyREN 对哦。所以题主这个需求场景很奇怪,感觉可以从业务需求层面再考虑一下技术需求。
    yellowtail
    yellowtail
    OP
    Feb 15, 2021
    4
    @hannibalm 感谢回复,已经重新用 dataframe 了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2235 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 00:18 · PVG 08:18 · LAX 16:18 · JFK 19:18
    ♥ Do have faith in what you're doing.