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
bin222
V2EX  ›  Python

Pandas groupby 的问题

  •  
  •   bin222 · 2018-07-30 16:07:50 +08:00 · 1508 次点击
    这是一个创建于 2096 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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  
       2018-07-30 17:21:09 +08:00
    a 当了 groupby 的条件之后, 变成结果的索引了呀,dataframe 又没有其他的列,所以返回的数据为空。
    shenxgan
        2
    shenxgan  
       2018-07-30 17:44:18 +08:00
    #1 1 楼说的很对



    可以这样做:
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5155 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 01:21 · PVG 09:21 · LAX 18:21 · JFK 21:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.