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
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 =
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

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

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to generate rows based on values in a column to fill missing values codesmatter 1 187 Oct-31-2020, 12:05 AM
Last Post: Larz60+
  Pandas, Assign a value in a row, to another column based on a condition klllmmm 6 486 Oct-16-2020, 04:43 PM
Last Post: klllmmm
  How to melt dataframe multiple columns to one column Mekala 1 242 Sep-24-2020, 08:32 PM
Last Post: scidam
  How to diff pandas rows and modify column value Mekala 1 148 Sep-18-2020, 12:38 PM
Last Post: Mekala
  5 variants to invert dictionaries with non-unique values Drakax1 2 285 Aug-31-2020, 11:40 AM
Last Post: snippsat
  Assigning Column nunique values to another DataFrame column Pythonito 1 355 Jun-26-2020, 06:52 AM
Last Post: hussainmujtaba
  Finding Max and Min Values Associated with Unique Identifiers in Python ubk046 1 316 May-08-2020, 12:04 PM
Last Post: anbu23
  Merge CSV Column using Pandas Data Frames davidlang 1 712 May-01-2020, 02:43 PM
Last Post: klllmmm
  Get values from a split column Pythonito 3 484 Apr-18-2020, 11:35 PM
Last Post: Larz60+
  deleting the columns using column name dkirandasari 0 265 Apr-07-2020, 12:00 PM
Last Post: dkirandasari

Forum Jump:

User Panel Messages

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