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

怎么使用 pd,构建一对多的表格数据呢?

  •  
  •   wliansheng · Dec 5, 2022 · 2788 views
    This topic created in 1390 days ago, the information mentioned may be changed or developed.

    请问这种使用 DataFrame 该如何实现?

    图片注释
    5 replies  •  2022-12-08 15:04:15 +08:00
    lookStupiToForce
        1
    lookStupiToForce  
       Dec 5, 2022   ❤️ 1
    two methods:

    1. multi level index
    intuitive but not recommended
    https://pandas.pydata.org/docs/user_guide/advanced.html

    2. duplicate values in first two columns to match third columns row count
    noahliaszn
        2
    noahliaszn  
       Dec 6, 2022   ❤️ 1
    ![test]( https://imgur.com/a/IdTSN4N) 不知道是不是你想要的 其实楼上也给出方案了
    wliansheng
        3
    wliansheng  
    OP
       Dec 6, 2022
    @lookStupiToForce
    @Alias4ck 十分感谢。
    craiiz
        4
    craiiz  
       Dec 8, 2022
    这个比较像透视表吧?直接 pd.pivot_table(df, index=["用户", "联系方式等信息"]) 应该就行了
    wliansheng
        5
    wliansheng  
    OP
       Dec 8, 2022
    @craiiz 感谢帮助,我去试试
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1132 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 17:45 · PVG 01:45 · LAX 10:45 · JFK 13:45
    ♥ Do have faith in what you're doing.