How do I solve this specific Pandas Type Error

Viewed 31

I am using the groupby method to combine the cell values (strings) of a column:

dfz = dfy.groupby('Type ').agg({'Initial ':lambda x: '/'.join(x.unique()),2021:'sum',2022:'sum'}).reset_index()

The following error message appears:

TypeError: Sequence item 0: expected str instance, float found

1 Answers

join method input a tuple or array of strings, try this:

dfz = dfy.groupby('Type ').agg({'Initial ':lambda x: '/'.join([str(r) for r in x.unique()]),2021:'sum',2022:'sum'}).reset_index()
Related