Skip to content
Advertisement

How to append two rows from dataframe in a single row?

I have dataframe like below:

import pandas as pd

JavaScript

Output:

JavaScript

i want to append two rows into single row by using Gender (both F and M should be in one row). i dont bother on increasing the columns

My expected output should be:

JavaScript

Any suggestions how to do this would be helpful.

Advertisement

Answer

Split the dataframe into two dataframes (one for Gender = 'F' and one for Gender = 'M') and concatenate them:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement