Open jmcnamara opened 1 year ago
ExcelWriter: This is mainly done. The interface is meant to be simple/minimal and most of the applicable CvsWriter
features are already implemented.
The features of Polars Python ExcelWriter are shown below along with their equivalent polars_excel_writer
APIs and level of completeness:
Workbook | IO[bytes] | Path | str | None = None
,str | None = None
,
PolarsXlsxWriter::add_worksheet()
PolarsXlsxWriter::set_worksheet_name()
tuple[int, int] | str = "A1"
,
PolarsXlsxWriter::write_dataframe_to_cell()
str | dict[str, Any] | None = None
,
Table
APIs and set_table()
. No need for a separate API.str | None = None
,
Table
APIs and set_table()
. No need for a separate API.ColumnFormatDict | None = None
,dict[OneOrMoreDataTypes, str] | None = None
,ConditionalFormatDict | None = None
,dict[str, Any] | None = None
,ColumnTotalsDefinition | None = None
,ColumnWidthsDefinition | None = None
,RowTotalsDefinition | None = None
,dict[int | tuple[int, ...], int] | int | None = None
,dict[str, Sequence[str] | dict[str, Any]] | None = None
,dict[str, str | dict[str, str]] | None = None
,int = 3
,
PolarsXlsxWriter::set_float_precision()
bool = True
,
PolarsXlsxWriter::set_header()
bool = True
,
PolarsXlsxWriter::set_autofilter()
bool = False
,
PolarsXlsxWriter::set_autofit()
Sequence[str] | SelectorType | None = None
,bool = False
,int | None = None
,
PolarsXlsxWriter::set_zoom()
tuple
The
polars_excel_writer
crate is a library for serializing Polars dataframes to Excel Xlsx files.It provides two interfaces for writing a dataframe to an Excel Xlsx file:
ExcelWriter
a simple Excel serializer that implements the PolarsSerWriter
trait to write a dataframe to an Excel Xlsx file.PolarsXlsxWriter
a more configurable Excel serializer that more closely resembles the interface options provided by the Polarswrite_excel()
dataframe method.ExcelWriter
usesPolarsXlsxWriter
to do the Excel serialization which in turn uses therust_xlsxwriter
crate.Example
An example of writing a Polar Rust dataframe to an Excel file using the
ExcelWriter
interface.Second output file (same as the first):
Performance
The table below shows the performance of writing a dataframe using Python Polars, Python Pandas and
PolarsXlsxWriter
.Performance data:
Polars
Pandas
polars_excel_writer
polars_excel_writer
+zlib
The tested configurations were:
Polars
: The dataframe was created in Python Polars and written using thewrite_excel()
function. See [perf_test.py
].Pandas
: The dataframe was created in Polars but converted to Pandas and then written via the Pandas [to_excel()
] function. See also [perf_test.py
].polars_excel_writer
: The dataframe was created in Rust Polars and written using thePolarsXlsxWriter
interface. See [perf_test.rs
].polars_excel_writer
+zlib
: Same as the previous test case but uses thezlib
feature flag to enable the C zlib library in conjunction with the backendZipWriter
.Note: The performance was tested for the dataframe writing code only. The code used to create the dataframes was omitted from the test results.
[
perf_test.py
]: https://github.com/jmcnamara/polars_excel_writer/blob/main/examples/perf_test.py [perf_test.rs
]: https://github.com/jmcnamara/polars_excel_writer/blob/main/examples/perf_test.rs [to_excel()
]: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_excel.htmlwrite_excel()
: https://pola-rs.github.io/polars/py-polars/html/reference/api/polars.DataFrame.write_excel.html#polars.DataFrame.write_excel