Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)
recategorized by

I have the dataframe like this

    Col1           Col2

['joe', 'joe']     ['joe']

['sam','bob']     ['sam'.'bob']

['mary','mary']   ['mary']

I want to use an apply function on Col1 to get my result in Col2. Meaning, I want my lists with the duplicates in Col1 to no longer have those duplicates in Col2. Tried various functions with an applying and set, no dice. Seems like it should be straightforward.

1 Answer

0 votes
by (36.8k points)

For get col two

df['ColB'] = df['Col1'].explode().groupby(level=0).unique()

 Want to be a Data Science expert? Come and join this Data Science Courses

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...