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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get an average of the unique values of a column with group by condition and assign it klllmmm 0 266 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  Converting column of values into muliple columns of counts highland44 0 251 Feb-01-2024, 12:48 AM
Last Post: highland44
  Python Alteryx QS-Passing pandas dataframe column inside SQL query where condition sanky1990 0 728 Dec-04-2023, 09:48 PM
Last Post: sanky1990
  need to compare 2 values in a nested dictionary jss 2 854 Nov-30-2023, 03:17 PM
Last Post: Pedroski55
  Loop through values and compare edroche3rd 6 682 Oct-18-2023, 04:04 PM
Last Post: edroche3rd
  pandas : problem with conditional filling of a column Xigris 2 629 Jul-22-2023, 11:44 AM
Last Post: Xigris
  Trying to compare string values in an if statement israelsattleen 1 541 Jul-08-2023, 03:49 PM
Last Post: deanhystad
  highlight the columns and capture amy83 0 800 Mar-24-2023, 07:19 PM
Last Post: amy83
  PowerBI: Using Python Regex to look for values in column MarcusR44 1 967 Oct-14-2022, 01:03 PM
Last Post: ibreeden
  How to use pandas to compare two DataFrames having different structure traja47 0 775 Sep-24-2022, 08:07 AM
Last Post: traja47

Forum Jump:

User Panel Messages

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