推荐学习书目
› 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 索引相关,请问如何快速实现在每个索引元素后面额外顺序增加索引元素

  •  
  •   yellowtail · Sep 22, 2020 · 1712 views
    This topic created in 2202 days ago, the information mentioned may be changed or developed.

    比如有 [ 1,5,11,17 ] 索引,现在需要在每个索引元素后面顺序增加两个额外索引元素变为 [ 1,2,3,5,6,7,11,12,13,17,18,19 ]

    想过在 dataframe 里增加一个真值列,然后 shift 几次叠加,但是用数量大了以后反复敲 shift 太傻了。。。

    一下想不出好办法,求思路

    Supplement 1  ·  Sep 22, 2020
    ```
    def fuc_a(a, b):
    if b == 1:
    return a | {i+1 for i in a}
    else:
    return fuc_a(fuc_a(a,b-1),1)
    ```
    冥思苦想一小时...用集合加递归解决了
    yellowtail
        1
    yellowtail  
    OP
       Sep 22, 2020
    ```
    def fuc_a(a, b):
    if b == 1:
    return a | {i+1 for i in a}
    else:
    return fuc_a(fuc_a(a,b-1),1)
    ```
    冥思苦想一小时...用集合加递归解决了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2203 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 06:06 · PVG 14:06 · LAX 23:06 · JFK 02:06
    ♥ Do have faith in what you're doing.