1

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?

1 Answer 1

2

Try using:

df['col'] = df.apply(lambda x: x['Responsibility Type'] in x['Roles'], axis=1)
print(df)
Sign up to request clarification or add additional context in comments.

2 Comments

It doesn't work. I need it to return a boolean if true or false row by row
@PauloCortez Try again, i edited it, please accept if it works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.