I have a polars dataframe that I want to group by and concatenate the unique values in as a single entry.
in pandas, I go:
def unique_colun_values(x):
return('|'.join(set(x)))
dd=pd.DataFrame({'col1':[1,1,2,3,4],'col2':['a','a','a','b','b'],'col3':['qwe','rty','asd','fgh','zxc']})
dd.groupby('col1').agg(lambda x: unique_colun_values(x))
This works fine
when I try to implement in polars:
pl.from_pandas(dd).group_by('col1').agg(lambda x: unique_colun_values(x), allow_object=True)
I get the following error:
TypeError: cannot create expression literal for value of type function.
Hint: Pass `allow_object=True` to accept any value and create a literal of type Object.
Am I missing something?