Back

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

I have the dataframe like this:

d = {'repeat': [23, 25,23], 'unique': [1,2,3]}

df = pd.DataFrame(data=d)

Using the pandas built-in function the dataframe of this form:

grouped = {'unique': [[1,3],[2]], 'repeat': [23,25]}

dg =pd.DataFrame(data=grouped)

df -- pandas built-in operations --> dg?

1 Answer

0 votes
by (36.8k points)

You can use a groupby and agg like this:

df.groupby("repeat").agg(lambda x: list(x)).reset_index()

 Want to be a master in Data Science? Enroll in this Data Science Courses

Browse Categories

...