I have an excel file that has conditional formatting with red color in certain rows one of the columns. So my file looks like this
Now I have to apply the filter on the "College" column to delete all the rows that have a red-colored background.
And save it back to the file.
The code I wrote for this is:
dataFrame_file = pd.read_excel(util.comcastFile2Path(), sheet_name='Sheet1') //comcastFile2Path() gives path of file
def only_cells_with_red_background(cell):
return cell if cell.style.bg_color in {utils.colors.red, 'FFFF0000'} else np.nan
df=dataFrame_file.style.applymap(only_cells_with_red_background,subset=['College'])
util.mergeFile(dataFrame_file,df,util.comcastFile2Path)
And my util class method for merging and saving file looks like this
def mergeFile(dataFrame_file, delete_frame, comcastFileName):
dataFrame_file = dataFrame_file.merge(delete_frame, how='left', indicator=True).query(
'_merge == "left_only"').drop('_merge', 1)
saveFile(dataFrame_file,comcastFileName)
When I do this the error I get is:
TypeError: Can only merge Series or DataFrame objects, a <class 'pandas.io.formats.style.Styler'> was passed
How can I move further with this?
Thanks in advance.