modin.pandas.DataFrameGroupBy.groups¶
- property DataFrameGroupBy.groups: PrettyDict[Hashable, pd.Index][source]¶
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'])
Groupby one column and get the label of each member of each group.
>>> df.groupby('A').groups {1: [0, 1, 3], 2: [2, 4]}
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]}
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.