Skip to content

DataFrames

Rahmad Afandi edited this page Jun 7, 2026 · 1 revision

DataFrames

.sheet(name, data) accepts pandas and polars DataFrames directly.

import pandas as pd, polars as pl
from rustpy_xlsxwriter import FastExcel

FastExcel("pandas.xlsx").sheet("S", pd.DataFrame({"a": [1, 2], "b": ["x", "y"]})).save()
FastExcel("polars.xlsx").sheet("S", pl.DataFrame({"a": [1, 2], "b": ["x", "y"]})).save()

How input is detected

The writer inspects the object in this order (data_types.rs):

  1. __arrow_c_stream__Arrow zero-copy (fastest)
  2. get_column + schema → polars fallback
  3. columns → pandas fallback
  4. otherwise → records (list/generator of dicts)

Arrow zero-copy

pandas ≥ 2.0 and polars both expose the Arrow C-Stream interface, so column data is read straight from the Arrow buffers with no per-value Python conversion. This is the fast path and is taken automatically — you don't do anything special.

Supported Arrow column types: all integer/unsigned widths, Float16/32/64, Boolean, Utf8/LargeUtf8/Utf8View, Date32/Date64, and Timestamp (s/ms/µs/ns). Unsupported types are written as empty cells.

Fallback path & memory

If the Arrow path is unavailable (e.g. old pandas without __arrow_c_stream__, or exotic dtypes), the writer materializes each column as a Python list (to_list/tolist). That path is O(rows) memory per column — not constant memory. Modern pandas/polars hit the Arrow path instead, so this only affects legacy setups.

Datetime columns

Temporal columns get the datetime_format applied automatically (default ISO yyyy-mm-ddThh:mm:ss). Override per sheet:

FastExcel("dates.xlsx").format(datetime_format="dd/mm/yyyy").sheet("S", df).save()

NaN / Inf

NaN and ±Inf floats are written as empty cells (both Excel and CSV).

Clone this wiki locally