I have a simple dataframe (df) like shown below:
index Job Person
1 j1 Cathy
2 j2 Mark
3 j3 Cathy
4 j4 Steve
5 j5 Cathy
6 Cathy
7 j1 Cathy
I would like to convert the above dataframe as:
Person CountJob JobDetails
Cathy 4 j1;j3;j5
Mark 1 j2
Steve 1 j4
i.e, drop the Nulls and join Unique jobs for each person.
I can partially solve this using groupby :
df.groupby('Person').agg(CountJob=('Job','count'),
JobDetails=('Job',lambda x: ';'.join(x.dropna()))
)
I am able to drop null values but can't seem to get unique values; in the above example, for 'Cathy', 'JobDetails' becomes j1;j3;j5;j1