我们可以在 pandas.core.groupby.SeriesGroupBy 对象中看到组数据吗

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40630506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 02:26:49  来源:igfitidea点击:

Can we see the group data in pandas.core.groupby.SeriesGroupBy object

pythonpandas

提问by ben

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

我们可以检查pandas.core.groupby.SeriesGroupBy对象中的数据吗?

回答by IanS

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_groupmethod.

第二个选项:如果您想查看特定值的组,请使用该get_group方法。

df.groupby(column).get_group(name)

回答by serv-inc

Sure, just use

当然,只需使用

df.groupby(column).head()

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

显示前 n 行(默认值:5)。