Bottom Page

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

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Finding Max and Min Values Associated with Unique Identifiers in Python ubk046 1 97 May-08-2020, 12:04 PM
Last Post: anbu23
  Merge CSV Column using Pandas Data Frames davidlang 1 462 May-01-2020, 02:43 PM
Last Post: klllmmm
  Get values from a split column Pythonito 3 185 Apr-18-2020, 11:35 PM
Last Post: Larz60+
  deleting the columns using column name dkirandasari 0 96 Apr-07-2020, 12:00 PM
Last Post: dkirandasari
  Python script merging some columns to one column with new name jbveenstra 6 322 Feb-13-2020, 02:01 PM
Last Post: jbveenstra
  How to calculate unique rows column sum and percentage SriRajesh 4 321 Feb-12-2020, 02:21 PM
Last Post: SriRajesh
  Getting duplicate column values but same row values from a csv smidtol 1 206 Feb-10-2020, 08:43 PM
Last Post: Larz60+
  Do Calculation between Rows based on Column values - Pandas Dataframe ahmedwaqas92 0 258 Jan-28-2020, 07:06 AM
Last Post: ahmedwaqas92
  Search Excel column values jonzee 1 467 Dec-21-2019, 02:38 AM
Last Post: Clunk_Head
  Highlight and remove specific string of text itsalmade 5 425 Dec-11-2019, 11:58 PM
Last Post: micseydel

Forum Jump:

Users browsing this thread: 1 Guest(s)