Reputation: 404
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.
Upvotes: 0
Views: 148
Reputation: 862521
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]
Upvotes: 1