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

pandas 有那种根据开头匹配合并的函数吗?

  •  
  •   kevinfk2 · May 18, 2021 · 1870 views
    This topic created in 1826 days ago, the information mentioned may be changed or developed.
    A C
    qwer qwer1234
    asdf asdf11
    zxcv zxcv55
    aa aass111

    像这样 A 列是 C 列的开头就匹配合并。

    找半天没找到合适的。

    求大佬指教。
    5 replies    2021-05-19 13:58:26 +08:00
    Yinz
        1
    Yinz  
       May 18, 2021   ❤️ 1
    自己写个函数用 startswith 函数判断并处理,然后通过 DataFrame.apply 调用你写的函数对 dataframe 进行处理
    Hieast
        2
    Hieast  
       May 18, 2021
    @Yinz #1 感觉你说得对,但是效率应该也不高,为啥不直接 iter row 呢,直接循环可以免去理解 apply 的各种高级参数的含义
    Yinz
        3
    Yinz  
       May 19, 2021
    @Hieast #2 改 apply 是常见优化 iterrow 效率的方法了,另外 itertuple 效率也比 iterrow 高。当然,iter 系列函数是好理解一点。
    Hieast
        4
    Hieast  
       May 19, 2021
    @Yinz 有什么资料讲过 apply 什么样的函数能够提高效率么?我一直以为数字运算才可以
    kevinfk2
        5
    kevinfk2  
    OP
       May 19, 2021
    @Yinz
    @Hieast

    startswith 可以
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3085 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 49ms · UTC 12:04 · PVG 20:04 · LAX 05:04 · JFK 08:04
    ♥ Do have faith in what you're doing.