How can I implement a custom pandas.Grouper class?
In other words - which methods/interfaces should the subclass of pandas.Grouper implement so that it can operate as an argument of DataFrame.groupby?
As a brief toy example: writing a grouper class that will group dataframe based on the first 5 symbols of some particular column of strings. Indeed this is easily achieved using existing methods:
df.groupby(df[column].str[:5])
But what I'm looking for is implementing some NameGrouper class, so that the operation is done by:
df.groupby(NameGrouper(column))
p.s. There're quite some questions on SO about tailoring group-by to a particular needs (e.g. Pandas: Custom group-by function, Pandas customized group aggregation, Pandas groupby custom groups) with answers using standard pandas functionality. But what I'm interested in an extension of the default pandas functionality.