0

I have a dataframe with one column of last names, and one column of first names. How do I merge these columns so that I have one column with first and last names?

Here is what I have: First Name (Column 1)

John
Lisa
Jim

Last Name (Column 2)

Smith

Brown

Dandy

This is what I want:

Full Name

John Smith

Lisa Brown

Jim Dandy.

Thank you!

1
  • df["Full Name"] = df["First Name"] + ' ' + df["Last Name"] df.drop[["First Name", "Last Name"]], 1) Commented Jun 5, 2017 at 20:08

2 Answers 2

5

Try

df.assign(name = df.apply(' '.join, axis = 1)).drop(['first name', 'last name'], axis = 1)

You get

    name
0   bob smith
1   john smith
2   bill smith
Sign up to request clarification or add additional context in comments.

Comments

4

Here's a sample df:

df
  first name last name
0        bob     smith
1       john     smith
2       bill     smith

You can do the following to combine columns:

df['combined']= df['first name'] + ' ' + df['last name']

df
  first name last name    combined
0        bob     smith   bob smith
1       john     smith  john smith
2       bill     smith  bill smith

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.