python - Check if values of a column is in another column array in a pandas dataframe
问题描述
I have the following dataframe:
Person Number Responsibility Type Roles
0 10000170 DSC HR Business Partner [DSC Employee Custom, DSC HR Business Partner,...
1 10000479 DSC HR Business Partner [DSC Employee Custom, DSC HR Business Partner,...
2 10001347 DSC HR Business Partner [DSC HR Business Partner, DSC HR Business Part...
3 10001754 DSC HR Business Partner Approver [DSC Line Manager, DSC Employee Custom, DSC He...
4 10001754 DSC Head of HR [DSC Line Manager, DSC Employee Custom, DSC He...
I have 3 columns, where the column "Responsibility Type" hold string values and "Roles" is a list (or an array, any would work) with multiple values.
I want to check, row by row, if the value on the column "Responsibility Type" is in list of the "Roles" column.
Any idea how could I do that?
解决方案
Try using:
df['col'] = df.apply(lambda x: x['Responsibility Type'] in x['Roles'], axis=1)
print(df)
推荐阅读
- javascript - 在全局 ajaxForm 的每个实例中使用 beforeSend 和 complete
- python - 如何使用 python selenium 在 chrome 浏览器上单击下载图标
- r - 如何选择已以升序方式在其他行中排序的特定行?
- android - Android 依赖 'androidx.core:core' 有不同版本的编译(1.0.0-rc01)和运行时(1.0.2)类路径
- javascript - Javascript:即使不满足 IF 语句的所有条件,也会继续显示错误
- java - 我的 java SSHClient 类有问题,特别是 Expect 方法没有按预期返回数据,会发生什么?
- .net - 将日志文件输出发送到控制台
- android - 如何解决“被 Play Protect 屏蔽”的问题
- sql-server - 我无法恢复我的数据库 SQL Server Management Studio 无法识别我的 .bak 文件
- java - 在tomcat docker上部署java REST服务