Search code examples
pythonpandasdataframestyling

Make pandas to_excel stop styling


I'm using Pandas to edit an Excel file which other people are using. But when I save it using df.to_excel, Pandas adds an ugly looking black border to cells in the header and in the index. I want it to be written in a plain format, how a CSV file would look if I opened it up in Excel. It would be even better if it was written back using the same styles it was read in

Is there anyway to make df.to_excel write without styling or with the original styles?

Thanks.


Solution

  • Try this trick:

    import io
    
    pd.read_csv(io.StringIO(df.to_csv()), header=None)
      .to_excel("output.xlsx", header=None, index=None)