如果col的行中的str1 =另一个col的行中的str,则设置第三个col

问题描述

我有一个合并的数据框,其中我想对照“ right_side”列的行中的每个字符串检查“配置文件”列的行中包含的每个字符串。如果这两个字符串相等,我想用“ left_side”列中的str替换“ profile”列中的str。由于某种原因,我确实很难受,并且尝试了.loc,dict,map和.at方法,但是必须缺少一个组件,而每个组件都不起作用。这是数据框:

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

非常感谢您的帮助!

解决方法

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]

这是你的追求吗?

,

这是我尝试使用lambda:

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...