Problems writing to excel after sorting dataframe

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'])

Hi MT. You say:

“the below is giving me an error and I can’t figure out why”

At least you know what error it is giving. How are we supposed to figure it out when you don’t tell us the error?

In your response, please copy and paste the full traceback, starting from the line “Traceback…” and going all the way to the error message.

Thanks for looking into it, I actually got the solution