snowflake.snowpark.modin.plugin.extensions.groupby_overrides.SeriesGroupBy.groups

property SeriesGroupBy.groups: PrettyDict[Hashable, pd.Index][source] (https://github.com/snowflakedb/snowpark-python/blob/v1.26.0/snowpark-python/src/snowflake/snowpark/modin/plugin/extensions/groupby_overrides.py#L197-L209)

Get a dictionary mapping group key to row labels.

Returns:

Dict {group name -> group labels}.

Return type:

pandas.io.formats.printing.PrettyDict[Hashable, pandas.Index]

Examples

>>> df = pd.DataFrame({'A': [1, 1, 2, 1, 2],
...                    'B': [np.nan, 2, 3, 4, 5],
...                    'C': [1, 2, 1, 1, 2]}, columns=['A', 'B', 'C'])
Copy

Groupby one column and get the label of each member of each group.

>>> df.groupby('A').groups
{1: [0, 1, 3], 2: [2, 4]}
Copy

Group a dataframe with a custom index by two columns.

>>> df.set_index('A', inplace=True)
>>> df.groupby(['B', 'C']).groups
{(2.0, 2): [1], (3.0, 1): [2], (4.0, 1): [1], (5.0, 2): [2]}
Copy

Notes

Beware that the return value is a python dictionary, so evaluating this property will trigger eager evaluation of the pandas dataframe and will materialize data that could be as large as the size of the grouping columns plus the size of the index.

Language: English