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

pandas 链式赋值总得用 copy

  •  
  •   n2l · 2022-01-15 15:26:54 +08:00 · 1844 次点击
    这是一个创建于 898 天前的主题,其中的信息可能已经有所发展或是发生改变。

    总会遇到链式赋值的提醒,无奈只能反复用 copy ,请问有没有类似 c 指针之类的操作,我只想修改源数据,要这么多 copy 后的玩意儿干啥

    1 条回复    2022-01-15 15:41:53 +08:00
    imn1
        1
    imn1  
       2022-01-15 15:41:53 +08:00   ❤️ 1
    如果只是修改源数据,可以多用 inplace=True

    整列赋值的话,其实不多触发提醒,一般都是跨列赋值,或者 apply 才出现
    但这个东西确实是烦,没辙,谁叫 python 大部分变量都是引用呢

    如果只是部分行赋值,单值用 mask ,多值用 update ,index 匹配上就行了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1761 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 16:31 · PVG 00:31 · LAX 09:31 · JFK 12:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.