[Python] Polars.write_excel: How to remove thousand separator for i64 & f64 & remove trailing...

Discussão em 'Python' iniciado por Stack, Julho 16, 2025.

  1. Stack

    Stack Membro Participativo

    I used to code in python-pandas for my day-to-day work and now I'm moving to python-polars for a good change since it improves my productivity.

    Libraries I use: polars as pl polars.selectors as sc

    In my current project, I imported my data via pl.read_excel('abc.xlsx', engine='openpyxl') instead of the default engine since it gave me error on column that it can't detect dtype.

    My data consists of all kind of dtypes, and in particular, Int64 and Float64. Prior to exporting my data to .xlsx Excel workbook, I have had to use df = df.with_columns(sc.by_dtype(pl.Float64).round(2)) to round all Float64 columns to 2 decimal places. After that, I exported my data using pl.write_excel('abc_v2.xlsx').

    (1) Here comes the first problem: The Float64 columns shown in python are of 2 decimal places, but an extra trailing zero is added to the back of values in the output Excel file.

    Note: The original data in Excel are of 2 decimal places without trailing zero in all Float64 columns.

    (2) My second problem: Both Int64 and Float64 columns shown in python are without thousand separator but the thousand separator is introduced in the output Excel file.

    Note: The original data in Excel does not come with thousand separator in all Int64 and Float64 columns.

    Is there any fix to this problem with polars.write_excel()? I have no such issue with pandas.to_excel().

    Continue reading...

Compartilhe esta Página