V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · 1620 views
    This topic created in 1900 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
        1
    hannibalm  
       Feb 15, 2021
    数据库是集合概念,不加 order by 情况下,不保证每次取 a = 1 返回的行顺序相同
    dorothyREN
        2
    dorothyREN  
       Feb 15, 2021
    @hannibalm #1 加了 orderby 也不能保证吧。相同值的顺序
    hannibalm
        3
    hannibalm  
       Feb 15, 2021
    @dorothyREN 对哦。所以题主这个需求场景很奇怪,感觉可以从业务需求层面再考虑一下技术需求。
    yellowtail
        4
    yellowtail  
    OP
       Feb 15, 2021
    @hannibalm 感谢回复,已经重新用 dataframe 了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3452 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 04:23 · PVG 12:23 · LAX 21:23 · JFK 00:23
    ♥ Do have faith in what you're doing.