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

Pandas groupby 的问题

  •  
  •   bin222 · Jul 30, 2018 · 2281 views
    This topic created in 2984 days ago, the information mentioned may be changed or developed.
    import pandas as pd
    c=pd.DataFrame({'a':[1,2,3,1,2,1,1,1,1]})
    c.groupby('a').count()

    --------
    理论上应该有这个结果:
    a amount
    1 6
    2 2
    3 1

    ----------
    然鹅,是这个:
    Empty DataFrame
    Columns: []
    Index: [1, 2, 3]
    -------------------
    为什么呢?
    如果要形成想要的结果,应该怎么写呀,我想不明白哪儿错了
    enenaaa
        1
    enenaaa  
       Jul 30, 2018
    a 当了 groupby 的条件之后, 变成结果的索引了呀,dataframe 又没有其他的列,所以返回的数据为空。
    shenxgan
        2
    shenxgan  
       Jul 30, 2018
    #1 1 楼说的很对



    可以这样做:
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2221 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 00:49 · PVG 08:49 · LAX 17:49 · JFK 20:49
    ♥ Do have faith in what you're doing.