I'm processing a data set using Dask (considering it doesn't fit in memory) and I want to group the instances with a different aggregating function depending on the column and it's type.
Dask has a set of default aggregation functions for numerical data types, but not for strings/objects. Is there a way to implement a user defined aggregation function for strings somewhat similar to the example below?
atts_to_group = {'A', 'B'}
agg_fn = {
'C': 'mean' #int
'D': 'concatenate_fn1' #string - No default fn for strings - Doesn't work
'E': 'concatenate_fn2' #string
}
ddf = ddf.groupby(atts_to_group).agg(agg_fn).compute().reset_index()
At this point I'm able to read the whole data set in memory upon dropping irrelevant columns/rows, but I'd prefer continuing the processing in Dask considering it's faster performing the required operations.
Edit: Tried adding a custom function directly onto the dictionary:
def custom_concat(df):
...
return df_concatd
agg_fn = {
'C': 'mean' #int
'D': custom_concat(df)
}
-------------------------------------------------------
ValueError: unknown aggregate Dask DataFrame Structure: