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

pandas 相关,求教如何对 group 以后的每个 df 中生成一个新列,由 x['旧列']-x['旧列'].shift(1)生成

  •  
  •   yellowtail · Mar 12, 2021 · 1616 views
    This topic created in 2022 days ago, the information mentioned may be changed or developed.
    目的是做 A 股 K 线的校验,是否有缺失数据。
    逻辑是先给每行加一个某个上午或者下午的列,如 2021312AM 等,在 group 以后就得到每一个上、下午对应的 k 线 dfx 了。
    然后通过 apply 可以实现 dfx['校验信息'] =dfx['交易时间'] - dfx['交易时间'] .shift(1),只要校验信息为固定值就基本说明没有缺失(首尾另外校验)。

    def fuc(x):
    x['verifiy']= x['trade_date']-x['trade_date'].shift(1)
    dft.groupby('week_day').apply(lambda x:fuc(x))

    求教为什么这样写我最后的 dft 里没有出现 verifiy 列?
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   971 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 18:56 · PVG 02:56 · LAX 11:56 · JFK 14:56
    ♥ Do have faith in what you're doing.