Merge rows in a specific order

Nevermind the new dataset gave NaNs because it did not contain fitting data

I have a before and after survey and I want to create a dataset with rows containing all the results of one person. How do I concat the two dataframes making sure it takes the column ‘Full name’ as a reference point when it comes ordering the rows? Thank you!

concatenated = pd.concat([df, data], axis=1)

I tried this line of Python code but it does not order the rows.

Answer

maybe this helps you:

import pandas as pd
  
df1 = pd.DataFrame({'last_name': {0: "one", 1: "two", 2: "three"},
                   'first_name': {0: "four", 1: "five", 2: "six"}})

df2 = pd.DataFrame({'last_name': {0: "one", 1: "two", 2: "three"},
                   'Value1': {0: 10, 1: 11, 2: 16},
                   'Value2': {0: 27, 1: 23, 2: 21},
                   'Value3': {0: 43, 1: 33, 2: 17}})
print(df1)

print(df2)

final_df = df1.merge(df2, on='last_name', how='left')
final_df

output:

enter image description here

if you want concat, you can try this:

import pandas as pd
  
df1 = pd.DataFrame({'Date': {0: "first", 1: "second", 2: "third"},
                   'first_name': {0: "four", 1: "five", 2: "six"}})

df2 = pd.DataFrame({'Date': {0: "forth", 1: "fifth", 2: "sixth"},
                   'first_name': {0: "seve", 1: "eight", 2: "nine"}})

final_df = pd.concat([df1, df2,], axis=0)


final_df

output:

enter image description here