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
yellowtail
V2EX  ›  Python

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

  •  
  •   yellowtail · 2021-03-12 10:33:56 +08:00 · 703 次点击
    这是一个创建于 1134 天前的主题,其中的信息可能已经有所发展或是发生改变。
    目的是做 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 列?
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   956 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 19:47 · PVG 03:47 · LAX 12:47 · JFK 15:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.