0

I have a merged dataframe in which I would like to check each string contained in the row of the 'profile' column against each string in the row of the 'right_side' col. If these two strings are equal, I would like to replace the str in the 'profile' column with the str in the 'left_side' column. Am having a really hard time with this fro some reason and have tried, .loc, dict, map and .at methods but must be missing one component with each as nothing as worked. Here is the dataframe:

profile             left_side                       right_side
DevOps Developer    NaN                             NaN     
Software Developer  Software Development Developer  Software Developer
Software Developer  Software Development Developer  Software Developer
Quality Assurance   Quality Assurance Engineer      Quality Assurance

Thank you so much for the help!

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Erin
  • 465
  • 4
  • 11

2 Answers2

1
df.loc[(df["Profile"]==df["right_side"]),"Profile"]=df["left_side"]
print(df)

                          Profile  ...          right_side
0                DevOps Developer  ...                 NaN
1  Software Development Developer  ...  Software Developer
2  Software Development Developer  ...  Software Developer
3      Quality Assurance Engineer  ...   Quality Assurance

[4 rows x 3 columns]

Is this what you were after?

Gingerhaze
  • 664
  • 2
  • 5
  • 13
  • oh jeez, yes. I tried: df.loc[df.profile.isin(df.right_side), ["left_side"]] = df["left_side"] and was close but not quite there. Thank you!!! – Erin Sep 02 '20 at 19:46
1

Here's my attempt using lambda:

data["profile"] = data.apply(lambda x: x[1] if x[0] == x[2] else x[0], axis=1)
Maku
  • 1,476
  • 10
  • 21