Python Forum
How to compare two columns and highlight the unique values of column two using pandas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to compare two columns and highlight the unique values of column two using pandas
#1
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
Reply


Messages In This Thread
How to compare two columns and highlight the unique values of column two using pandas - by shubhamjainj - Feb-24-2020, 06:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Transform 3 Columns into Single Column DaveG 9 3,819 Mar-19-2025, 03:46 AM
Last Post: robbert23
  Highlight text with Reportlab beetlecad 2 2,674 Aug-07-2024, 09:36 AM
Last Post: Pedroski55
  Get an average of the unique values of a column with group by condition and assign it klllmmm 0 2,223 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  Converting column of values into muliple columns of counts highland44 0 975 Feb-01-2024, 12:48 AM
Last Post: highland44
  Python Alteryx QS-Passing pandas dataframe column inside SQL query where condition sanky1990 0 1,493 Dec-04-2023, 09:48 PM
Last Post: sanky1990
  need to compare 2 values in a nested dictionary jss 2 1,944 Nov-30-2023, 03:17 PM
Last Post: Pedroski55
  Loop through values and compare edroche3rd 6 2,086 Oct-18-2023, 04:04 PM
Last Post: edroche3rd
  pandas : problem with conditional filling of a column Xigris 2 1,585 Jul-22-2023, 11:44 AM
Last Post: Xigris
  Trying to compare string values in an if statement israelsattleen 1 1,264 Jul-08-2023, 03:49 PM
Last Post: deanhystad
  highlight the columns and capture amy83 0 1,350 Mar-24-2023, 07:19 PM
Last Post: amy83

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020