I am trying to write a pandas DataFrame to a .xlsx file, where different numeric columns will have different formats. For example, some of them will show only two decimal places, some of them will not be displayed, some will be formatted as percentages with the symbol "%", etc.
I noticed that DataFrame.to_html() has a formatters parameter that allows you to do just that by comparing different formats with different columns. However, there is no similar parameter in the DataFrame.to_excel() method. At most, we have a float_format that is global for all numbers.
I read a lot of SO posts that are at least partially related to my question, for example:
Are there even more convenient functions / properties related to Excel in the pandas API that can help here or something similar in openpyxl , or perhaps somehow point the output format metadata directly to each column in the DataFrame , which then will be interpreted downstream with different output?
source share