0

I have data with about 3 different columns in excel.

    COLUMN A = Product name_1
    Column B = type
    column C = PRODUCT NAME_2 .

I wanted to check the names in column C against column A and if it matches, then extract the corresponding column B value. Main excel sheet:

| column a | column b |column c|
| -------- | ---------|--------|
| apple    | 1        |  apple |
| microsoft| 0        |cognizant|
|google    |2         |amazon  |
|cognizant |0         |
|amazon    |1         |

and expected output as below:

    | column A | COLUMN b |
    | -------- | -------- |
    | apple    |  1       |
    | cognizant|  0       |
    |amazon    |  1       |

Can anyone suggest a function of code in which I can do this without actually having to go through all of them row by row?

Thanks

1 Answer 1

1

Use df.isin:

In [1668]: df[df['column a'].isin(df['column c'])][['column a', 'column b']]
Out[1668]: 
    column_a  column_b
0      apple         1
3  cognizant         0
4     amazon         1
Sign up to request clarification or add additional context in comments.

Comments

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.