Python Forum
How to compare two columns and highlight the unique values of column two using pandas - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to compare two columns and highlight the unique values of column two using pandas (/thread-24633.html)



How to compare two columns and highlight the unique values of column two using pandas - shubhamjainj - Feb-24-2020

I was using following conditional formatting code but it is not working :

#Data_analysis_std is excel file name
#pd is pandas object
writer = pd.ExcelWriter('Data_Analysis_Std.xlsx', engine ='openpyxl')
wb = writer.book
ws = writer.sheets['Sheet1']

red_background = PatternFill(bgColor=colors.RED)
diff_style = DifferentialStyle(fill=red_background)

rule = Rule(type="uniqueValues", dxf=diff_style)

#ws.conditional_formatting.add({2, previous_date_data_column, 2 ,current_date_data_column} ,rule)
ws.conditional_formatting.add('B:I' ,rule)
Above code "ws.conditional_formatting.add('B:I' ,rule)" is showing error because of range as i want to compare 2 columns that is column B and column I but here i am defining range, but i don't understand what is correct format. Or there is anyother way to compare two column please let me know

Error:
TypeError: expected <class 'openpyxl.worksheet.cell_range.MultiCellRange'>
If any other information required please let me know.
Thanks in advance