dimastbk / python-calamine

Python binding for Rust's library for reading excel and odf file - calamine.

Home Page:https://pypi.org/project/python-calamine/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

python-calamine

PyPI - Version Conda Version Python Version from PEP 621 TOML

Python binding for beautiful Rust's library for reading excel and odf file - calamine.

Is used

Installation

Pypi:

pip install python-calamine

Conda:

conda install -c conda-forge python-calamine

Example

from python_calamine import CalamineWorkbook

workbook = CalamineWorkbook.from_path("file.xlsx")
workbook.sheet_names
# ["Sheet1", "Sheet2"]

workbook.get_sheet_by_name("Sheet1").to_python()
# [
# ["1",  "2",  "3",  "4",  "5",  "6",  "7"],
# ["1",  "2",  "3",  "4",  "5",  "6",  "7"],
# ["1",  "2",  "3",  "4",  "5",  "6",  "7"],
# ]

By default, calamine skips empty rows/cols before data. For suppress this behaviour, set skip_empty_area to False.

from python_calamine import CalamineWorkbook

workbook = CalamineWorkbook.from_path("file.xlsx").get_sheet_by_name("Sheet1").to_python(skip_empty_area=False)
# [
# [",  ",  ",  ",  ",  ",  "],
# ["1",  "2",  "3",  "4",  "5",  "6",  "7"],
# ["1",  "2",  "3",  "4",  "5",  "6",  "7"],
# ["1",  "2",  "3",  "4",  "5",  "6",  "7"],
# ]

Also, you can use monkeypatch for pandas for use this library as engine in read_excel() (only pandas 2.0 and 2.1 are supported). Pandas 2.2 and above have built-in support of python-calamine.

from pandas import read_excel
from python_calamine.pandas import pandas_monkeypatch


pandas_monkeypatch()

read_excel("file.xlsx", engine="calamine")
#            1   2   3   4   5   6   7
# 0          1   2   3   4   5   6   7
# 1          1   2   3   4   5   6   7

Also, you can find additional examples in tests.

About

Python binding for Rust's library for reading excel and odf file - calamine.

https://pypi.org/project/python-calamine/

License:MIT License


Languages

Language:Python 59.4%Language:Rust 40.6%