0

I have a dataframe, I would like to find the common rows based on a specific columns.

packing_id  col1  col2  col3 col4
1            1.0  2.0
2            2.0  2.0
3            1.0  1.0
4            3.0  3.0
.             .    .
.             .    .

I would like to find the rows where the col1 and col2 values are the same. I tried np.where(df.col1==df.col2) but it is not the right approach. I would appreciate your advice. Thanks.

1

2 Answers 2

1

I think your soluton is good, only add 2 parameters to np.where:

df['new'] = np.where(df.col1==df.col2, 'same', 'no same') 

If need filter them:

df1 = df[df.col1==df.col2]
Sign up to request clarification or add additional context in comments.

Comments

1

This should be work. Thanks

df[df.col1==df.col2]

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.