snowflake.snowpark.modin.plugin.extensions.groupby_overrides.SeriesGroupBy.indices¶
- property SeriesGroupBy.indices: dict[collections.abc.Hashable, numpy.ndarray[Any, numpy.dtype[numpy.int64]]][source]¶
Get a dictionary mapping group key to row positions.
- Returns:
Dict {group name -> group positions}.
- Return type:
Dict[Any, np.array]
Examples
>>> df = pd.DataFrame({'A': [1, 1, 2, 1, 2], ... 'B': [np.nan, 2, 3, 4, 5], ... 'C': [1, 2, 1, 1, 2]})
Groupby one column and get the positions of each member of each group.
>>> df.groupby('A').indices {1: array([0, 1, 3]), 2: array([2, 4])}
Group the same dataframe with a different index. The result is the same because the row positions for each group are the same.
>>> df.set_index('B').groupby('A').indices {1: array([0, 1, 3]), 2: array([2, 4])}
Notes
Beware that the return value is a python dictionary, so evaluating this property will trigger evaluation of the pandas dataframe and will materialize data that could be as large as the size of the grouping columns.