I have a pandas data-frame (Pre_Final_DataFrame) that I am writing to excel.
I need to highlight a row in Excel if that corresponding row has a "No Match" word on any of the column that starts with 'Result_'.
So, I decided to go for an array to understand which one needed to be highlighted.
But now, I would prefer a way to highlight using a function as it is too slow. Kindly help me with this.
In Simple words, I am writing a dataframe to excel using Pandas and it has million records and I want a row to be highlighted in "Yellow" only when there is a No Match value present in any one of the column that has a name starting with " Result_"
The Expected result appears in excel looks like below,
Input codes to start with a dataframe:-
import pandas as pd
data = {
'ColA':[1, 1],
'ColB':[1, 1],
'Result_1':['Match', 'Match'],
'ColA1':[1, 2],
'ColB1':[1, 1],
'Result_2':['No Match', 'Match'],
}
Pre_Final_DataFrame = pd.DataFrame(data)
ResultColumns_df = Pre_Final_DataFrame.filter(like='Result_')
ResultColumns_df_false =ResultColumns_df[ResultColumns_df.values == "No Match"]
RequiredRows_Highlight = ResultColumns_df_false.index.tolist()
writer = pd.ExcelWriter(OutputName,date_format='%YYYY-%mm-%dd',datetime_format='%YYYY-%mm-%dd')
Pre_Final_DataFrame.to_excel(writer,'Sheet1',index = False)
writer.save()
Output Expected: