PyExcelerate is an accelerated Python library designed for quickly writing Excel XLSX files, with an emphasis on performance and efficient memory usage. It is currently at version 0.13.0 and supports both Python 2.7 and various Python 3 versions, though a strict release cadence is not always observed.
pip install pyexcelerateVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a new Excel workbook, add a sheet with a 2D array of data, apply some basic styling, and save the workbook to a file. It highlights the primary use case of bulk data writing.
For very large files and strict memory constraints, consider alternative libraries like XlsxWriter which offer a `constant_memory` option. Optimize data structures to reduce memory footprint before passing to PyExcelerate.
Minimize individual cell styling. Apply styles to entire rows, columns, or ranges where possible using `ws.set_row_style()`, `ws.set_col_style()`, or range styling to improve performance.
If encountering this issue, try to preprocess or segment string data, or consider using alternative libraries for string-heavy large datasets. Check GitHub issues for potential workarounds or updates.
Instantiate the `Workbook()` object once, then add all sheets using `wb.new_sheet()` before a single `wb.save()` call.
Install pyexcelerate using pip: `pip install pyexcelerate`
Ensure `pyexcelerate` is installed correctly (`pip install pyexcelerate`) and that there are no local Python files named `pyexcelerate.py` or `Workbook.py` in your project directory that could shadow the actual library module. The correct import is `from pyexcelerate import Workbook`.
Consider splitting your data into multiple smaller Excel files or using a different data storage format better suited for very large datasets.
Ensure your data types are consistent and handle potential edge cases (e.g., special characters, very long strings). For extremely large string-heavy dataframes, you might consider breaking them into smaller parts or checking for `pyexcelerate` updates that address large string handling. Temporarily converting problematic columns to strings before writing might also help.
Before writing the DataFrame to Excel, fill or convert `NaT` values in datetime columns. For example, use `df.fillna('')` or `df[datetime_column].apply(lambda x: None if pd.isna(x) else x)` to replace `NaT` with `None` or an empty string.