Removing pandas rows that columns don't match with the same values but include empty columns

Viewed 32

So I have these two pandas dfs and I know how to remove the rows that columns don't match with the same values, but I also want to keep the rows where one of the columns are empty (I don't want those to be removed).

   V1                 V2          V3
hello                 0            0
nice                  0            1
meeting               1            1
you                   1            0
hi                    0      
   V1                 V2          V3
hello                 0            0
meeting               1            1
hi                    0      

What I've tried:

df = df[df.V2 == df.V3]

Problem: it removes the rows with one empty column

1 Answers

Some good answers in the comments, here's another alternative:

df[df.V3.fillna(df.V2).eq(df.V2)]
Related