Issue
I have a DF that looks like this.
My desired output is a DF that looks like this:
Here's the code I've tried:
test = df.groupby('Group', as_index=True).agg(lambda x: '; '.join(el for el in x if el !=''))
But this gives me the below.
When I use (per this answer):
test = out.groupby('DocSetID', as_index=True).agg(lambda x: '; '.join(el for el in x if el !='').set(x))
I get an error reading:
AttributeError: 'str' object has no attribute 'set'
What am I doing wrong? How can the code be fixed to only include one of each value?
Solution
You are nearly there, you have to apply set
to the list of values to join:
test = out.groupby('DocSetID', as_index=True).agg(lambda x: '; '.join(set(el for el in x if el !='')))
Answered By - theophile
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.