0

I want to delete row only for different label. But for NaN and empty is still stay (not deleted)

Here's my data

    id      barcode_x     barcode_y A   B
0   7068    38927887      38927895  0   12
1   7068    38927895      38927895  0   1
2   7068    39111141      38927895  0   4
3   7116    73094237                18  309
4   7154    37645215      37645215  0   9
5   7342    86972909      NaN       7   25

Here's what I need

    id      barcode_x     barcode_y A   B
1   7068    38927895      38927895  0   1
3   7116    73094237                18  309
4   7154    37645215      37645215  0   9
5   7342    86972909      NaN       7   25

How suppose I do this?

Nabih Bawazir
  • 6,381
  • 7
  • 37
  • 70

1 Answers1

1

Compare by filling nan with the corresponding columns and select rows accordingly ( Pre work: Fill the empty cell with Nan) i.e

df[df['barcode_y'].fillna(df['barcode_x']) == df['barcode_x']]

     id  barcode_x   barcode_y   A    B
1  7068   38927895  38927895.0   0    1
3  7116   73094237         NaN  18  309
4  7154   37645215  37645215.0   0    9
5  7342   86972909         NaN   7   25
Bharath M Shetty
  • 30,075
  • 6
  • 57
  • 108