Q:

Pandas Conditional Formatting Removed in Excel

It's my first time formatting an Excel spreadsheet with Python using the Pandas module. 
My code is shown below:
writer = pd.ExcelWriter('%s.xlsx'%item,engine='xlsxwriter')
workbook  = writer.book
format1 = workbook.add_format({'bg_color': '#FFC7CE',
                           'font_color': '#9C0006'})

final.to_excel(writer, '%s.xlsx'%item) # Output results to an excel file
#item is simply the name of the excel document.
#final is the name of the data frame I am working with.
worksheet = writer.sheets['%s.xlsx'%item ]
worksheet.conditional_format('A1:CG350', {'type':     'cell',
                                'criteria': 'containing',
                                'value':     'X ',
                                'format':    format1})
writer.save()

My code executes just fine. Its when I go to open up the final excel spreadsheet that I run into the following error messages:
Excel Error Message 1 Link
Excel Error Message 2 Link
Basically, Excel forces me to remove the conditional formatting. I am running Python 3 and Excel 2016. Any body have any suggested solutions?
Thanks!

A:

The 'containing' criteria is associated with type 'text' not 'cell'.
If you change that your program will work as expected. Here is an example:
import pandas as pd

final = pd.DataFrame({'Data': ['fox red', 'red fox', 'fox red', 'red fox']})

item = 'foo'
writer = pd.ExcelWriter('%s.xlsx'% item, engine='xlsxwriter')

workbook  = writer.book
format1 = workbook.add_format({'bg_color': '#FFC7CE',
                               'font_color': '#9C0006'})

final.to_excel(writer, '%s.xlsx' % item)

worksheet = writer.sheets['%s.xlsx' % item]

worksheet.conditional_format('A1:CG350', {'type':     'text',
                                          'criteria': 'containing',
                                          'value':    'X ',
                                          'format':   format1})

writer.save()

Output:

