0

I am dealing with this example DataFrame:

         A      B        C
1       Cat      0     Missing
2       Dog    Dog     Match
3       Cat    Cat     Match

I would like to remove row[1] as it meets the condition of 'C' == "Missing" and 'A'.isin('B')

Could use help writing this.

Currently I have tried;

if df['C'] == "Missing":
   df = df.loc[~df.A.isin(B)]

But no luck thus far. Thanks.

2 Answers2

0

This should work:

b = df['B']
df = df[~((df['A'].isin(b)) & (df['C'] == 'Missing'))]
sjw
  • 6,213
  • 2
  • 24
  • 39
0

try df.loc[~(df['C'] == "Missing") & (df['A'].isin(df['B'].unique()))]

ktdrv
  • 3,602
  • 3
  • 30
  • 45
  • While this code may answer the question, providing additional context regarding **how** and **why** it solves the problem would improve the answer's long-term value. – Alexander Feb 23 '18 at 17:23