Reputation: 2938
Let's say I have a dataframe that looks like this:
How can I apply lambda on the dataframe to make FullName = FirstName + ' ' + LastName? As far as I know lambda in dataframes has 1 input only? Thanks!
Upvotes: 3
Views: 285
Reputation: 862481
I think apply
here is not neccesary, only join columns together with +
:
df['FullName'] = df.FirstName + ' ' + df.LastName
Or use Series.str.cat
:
df['FullName'] = df.FirstName.str.cat(df.LastName, sep=' ')
Solution with lambda
is possible, but slow:
df['FullName'] = df.apply(lambda x: x.FirstName + ' ' + x.LastName, axis=1)
Upvotes: 6