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.

0

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

3 Comments

I tried but it doesnt give this output, it rather gives output of the first row
@RiddhiDua I updated, see if it works now
Works perfect, Thankyou.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.