Reputation: 619
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?
Upvotes: 1
Views: 3869
Reputation: 71570
Try using:
df['col'] = df.apply(lambda x: x['Responsibility Type'] in x['Roles'], axis=1)
print(df)
Upvotes: 2