-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Description
Pandas's DataFrame and Series implementation of groupby accepts a mapper function as it's "by" parameter (named "Index" in dask).
If this by parameter is a callable, the data will be grouped according to the function's returned value.
The function is called with the dataframe indices.
Although it's not as important to me personally, the by parameter can be a variety of value types. lists of functions and mapping dictionaries are also supported.
A somewhat funny example can be:
def odd_or_even(i):
return "Even" if i % 2 == 0 else "Odd"
df.groupby(odd_or_even).get_group("Even")