0

I have a dataframe with firstname, middlename, lastname. How do I merge these columns so that I have one column with fullname including NULL for middlenname in between if it is not there in data ex: john?

df
  first_name middle_name last_name
0        bob           K     smith
1       john                 smith
2       bill           R     smith

output

  full_name
0 bobKsmith
1 john smith
2 billRsmith
3
  • can you provide the dictionary used to create dataframe? Commented Sep 2, 2020 at 21:56
  • import pandas as pd data = {'first_name': ['bob', 'john', 'bill'], 'middle_name': ['K','', 'R'], 'last_name': ['smith', 'smith', 'smith']} df = pd.DataFrame(data) Commented Sep 2, 2020 at 22:07
  • @Vedant - any luck Commented Sep 2, 2020 at 22:43

1 Answer 1

1

This works as expected:

df.replace('', " ", inplace = True)
df["concat"] = df.sum(axis = 1)
Sign up to request clarification or add additional context in comments.

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.