我有以下数据框:
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...
我有 3 列,其中“职责类型”列保存字符串值,“角色”列是具有多个值的列表(或数组,任何都可以)。
我想逐行检查“职责类型”列上的值是否在“角色”列的列表中。
知道我该怎么做吗?
最佳答案
尝试使用:
df['col'] = df.apply(lambda x: x['Responsibility Type'] in x['Roles'], axis=1)
print(df)
关于python - 检查某列的值是否位于 pandas 数据框中的另一个列数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59856823/