Can we see the group data in pandas.core.groupby.S

2020-08-22 03:41发布

问题:

Can we check the data in a pandas.core.groupby.SeriesGroupBy object?

回答1:

First option: iterate over all groups.

for name, group in df.groupby(column):
    print(name)
    print(group)
    print('\n')

Second option: if you want to see the group for a specific value, use the get_group method.

df.groupby(column).get_group(name)


回答2:

Sure, just use

df.groupby(column).head()

It shows you the first n rows (default: 5).



回答3:

Just adding list() should help but the structure isn't super useful in its raw form. It returns a list of tuples with index.



标签: python pandas