I’ve bee working to format a spreadsheet and ran into some errors. I initially had the below and everything was working fine:
finalDF = pd.DataFrame.from_dict(compareDictList)
def highlight_rows(row):
if row["Inconsistencies"] == "Y":
return['background-color: yellow'] * len(row)
formatted = finalDF.style.apply(highlight_rows, axis = 1)
formatted.to_excel("FinalReport.xlsx", index=False, columns=['XXXX', 'YYYY', 'ZZZZ'])
I then got a request to sort the data, but the below is giving me an error and I can’t figure out why:
finalDF = pd.DataFrame.from_dict(compareDictList)
sortedDF = finalDF.sort_values(by=['XXXX', 'YYYY'])
def highlight_rows(row):
if row["Inconsistencies"] == "Y":
return['background-color: yellow'] * len(row)
formatted = sortedDF.style.apply(highlight_rows, axis = 1)
formatted.to_excel("FinalReport.xlsx", index=False, columns=['XXXX', 'YYYY', 'ZZZZ'])