I'm looking to set the default number format when writing to Excel from a Pandas dataframe. Is this possible?
I can set the default date/datetime_format with the following, but couldn't find a way to set the default number format.
writer = pd.ExcelWriter(f'{file_variable}.xlsx', engine='xlsxwriter',datetime_format='MM/DD/YYYY')
Otherwise, I assume I'm going to have to assign worksheets to variables and loop through the rows for the specified columns to set the number format.
I got this format the floats to 1 decimal place.
but that alas is not perhaps all cases - no joy with say larger numbers and thousands separator
However the following seems to work
All taken from here: http://xlsxwriter.readthedocs.io/working_with_pandas.html
For what it's worth and because the question was also tagged for openpyxl, you can also also edit the default style of a whole workbook in openpyxl. This could make sense for the number format but can have unexpected consquences if things like the font size is changed, because other GUI elements are affected. The following should work, if used with caution.