How to preview rows after using .groupby() on a Pandas df/series

前端 未结 2 1192
滥情空心
滥情空心 2021-01-25 00:15

After using df.groupby(df.index.month) I would like to preview my DataFrame unfortunately .head removes the group formatting and df[

相关标签:
2条回答
  • 2021-01-25 01:09

    you can loop through test

    test = df.groupby("columnTitle")
    for each in test:
        print each[0] #columnTitle value
        print each[1] #corresponding df equivalent of df[df['columnTitle']==each[0]]
    
    0 讨论(0)
  • 2021-01-25 01:10

    Something like this? gb is the GroupBy object. This prints the first 5 rows from the first 3 groups.

    In [230]: gb = df.groupby(df.index.month)
    
    In [231]: for k in gb.groups.keys()[:3]:
         ...:     print gb.get_group(k)[:5]
    
    0 讨论(0)
提交回复
热议问题