plydata.one_table_verbs.group_indices

class plydata.one_table_verbs.group_indices(*args, **kwargs)[source]

Generate a unique id for each group

Parameters
datadataframe, optional

Useful when not using the >> operator.

argsstrs, tuples, optional

Expressions or (name, expression) pairs. This should be used when the name is not a valid python variable name. The expression should be of type str or an interable with the same number of elements as the dataframe. As this verb returns an array, the tuples have no added benefit over strings.

kwargsdict, optional

{name: expression} pairs. As this verb returns an array, keyword arguments have no added benefit over str positional arguments.

Returns
outnumpy.array

Ids for each group

Examples

>>> import pandas as pd
>>> df = pd.DataFrame({'x': [1, 5, 2, 2, 4, 0, 4],
...                    'y': [1, 2, 3, 4, 5, 6, 5]})
>>> df >> group_by('x')
groups: ['x']
   x  y
0  1  1
1  5  2
2  2  3
3  2  4
4  4  5
5  0  6
6  4  5
>>> df >> group_by('x') >> group_indices()
array([1, 4, 2, 2, 3, 0, 3])

You can pass the group column(s) as parameters to group_indices

>>> df >> group_indices('x*2')
array([1, 4, 2, 2, 3, 0, 3])