0
Name Age Gender Occupation
Joey 18
Joey Male
Joey Engineer

I tried groupby().first() but that doesn't work because it gives such a table:

Name Age Gender Occupation
Joey 18

But I want a table like this:

Name Age Gender Occupation
Joey 18 Male Engineer

I have table like this, and I want to merge all the rows by name and get age, gender and occupation in the same row.

1 Answers1

1

You can replace '' with NaN, groupby "Name", then use first:

df = df.replace('', np.nan).groupby('Name').first().reset_index()

Output:

   Name   Age Gender Occupation
0  Joey  18.0   Male   Engineer