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

  •  
  •   yellowtail · 2020-09-22 17:32:55 +08:00 · 924 次点击
    这是一个创建于 1311 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

    第 1 条附言  ·  2020-09-22 19:58:09 +08:00
    ```
    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
       2020-09-22 19:57:13 +08:00
    ```
    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)
    ```
    冥思苦想一小时...用集合加递归解决了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2795 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 15:38 · PVG 23:38 · LAX 08:38 · JFK 11:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.