Skip to content
Advertisement

how to ignore null values in DataFrame when comparing columns

I am new to Pandas and learning. I am reading excel to DataFrame and comparing columns and highlight the column that’s not same. For example if Column A is not same as Column B then highlight the Column B. However I have some null values in Column A and Column B. When I execute the code, I don’t want to highlight the null values in Column B. How can I do that? Below is my code:

JavaScript

df before color function:

JavaScript

Output after running script:

enter image description here

Expected output:

enter image description here

Advertisement

Answer

The issue here is NaN == NaN will return False

JavaScript

More Info

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement