Neha
Neha

Reputation: 3

How to get a combined column with NULL string as well if exists in a python dataframe

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

Upvotes: 0

Views: 28

Answers (1)

Multivac
Multivac

Reputation: 815

This works as expected:

df.replace('', " ", inplace = True)
df["concat"] = df.sum(axis = 1)

Upvotes: 1

Related Questions