Home > database >  How to highlight differences between the two data frames in pandas
How to highlight differences between the two data frames in pandas

Time:01-04

I have two data frames with identical columns in pandas, we have index at column A

Actual:

  A      B       C 
  1     apple   red
  2     berry   blue 
  3    grapes   green

second data frame

Expected:

  A    B     C
  1   apple  green
  2   guava  blue
  3   grapes  green

Now I need to compare the two data frames and highlight mismatched cells with in data frame and then export the output to excel.

My code:

import pandas as pd

pd.concat([pd.concat([actual,expected,expected]).drop_duplicates(keep=False)]).to_excel(.......)

output:

  A   B   C
  1  apple red
  2  berry blue

I need to highlight red and berry

CodePudding user response:

This can be easily done with StyleFrame as shown in this post: enter image description here

CodePudding user response:

There is a function - compare, which help you to compare two datasets: Output

  •  Tags:  
  • Related