Issue
First data frame:
name age sex
smith row 26 male
sam smith 30 male
susan storm 25 female
Second data frame:
name age sex nick_name
smith row 26 male smity
sam smith 30 male sammy
susan storm 25 female suanny
Output expected:
name age sex
smith row 26 male
sam smith 30 male
susan storm 25 female
smity m
sammy m
suanny f
How can I dynamically map from other df to other df column?
Solution
You will have to modify df2 to get the result you want.
df2['name'] = df2['nick_name']
df2['sex'] = df2['sex'].str[0]
df2 = df2.drop(columns=['age', 'nick_name'])
df3 = pd.concat([df1, df2], ignore_index=True)
this is the end result
name age sex
smith row 26 male
sam smith 30 male
susan storm 25 female
smity NaN m
sammy NaN m
suanny NaN f
Answered By - Triky
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.