Skip to main content

Rearrange data from a normalized CSV format to a crosstabulated format, with styling.

Project description

crosstab

ci/cd Documentation Status PyPI Latest Release PyPI Downloads Python Version Support

crosstab is a Python package that rearranges data from a normalized CSV format to a crosstabulated format, with styling.

Go from this:

Crosstab Input

To this:

Crosstab Output

Installation

You can install crosstab via pip from PyPI:

pip install crosstab

There is also a Docker image available on the GitHub Container Registry:

docker pull ghcr.io/geocoug/crosstab:latest

Usage

The following examples demonstrate how to use crosstab to crosstabulate a CSV file. By default, the output is an Excel file with two sheets: one that contains metadata about the crosstabulation (ie. who ran the script, when it was run, etc.) and another with the data crosstabulated. If the keep_sqlite parameter is set to True, the SQLite database used to store the source data is kept. The SQLite file will have the same basename as the input CSV file, but with a .sqlite extension. If the keep_src parameter is set to True, the source CSV data is copied to the Excel file as a third sheet.

Each of the examples below will produce the exact same output.

Python

from pathlib import Path

from crosstab import Crosstab

Crosstab(
    incsv=Path("data.csv"),
    outxlsx=Path("crosstabbed_data.xlsx"),
    row_headers=("location", "sample"),
    col_headers=("cas_rn", "parameter"),
    value_cols=("concentration", "units"),
    keep_sqlite=True,
    keep_src=True,
).crosstab()

Command Line

crosstab -k -s -f data.csv -o crosstabbed_data.xlsx -r location sample -c cas_rn parameter -v concentration units

Docker

docker run --rm -v $(pwd):/data ghcr.io/geocoug/crosstab:latest -k -s -f /data/data.csv -o /data/crosstabbed_data.xlsx -r location sample -c cas_rn parameter -v concentration units

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crosstab-0.0.15.tar.gz (49.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

crosstab-0.0.15-py3-none-any.whl (34.7 kB view details)

Uploaded Python 3

File details

Details for the file crosstab-0.0.15.tar.gz.

File metadata

  • Download URL: crosstab-0.0.15.tar.gz
  • Upload date:
  • Size: 49.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for crosstab-0.0.15.tar.gz
Algorithm Hash digest
SHA256 25b651231d8fb7d1e733f61cce594481dfd44417a41485d2e82701dfea31f016
MD5 765a49656f7d5eaeb9d543ea31a86b45
BLAKE2b-256 5272998a9c35334c8a78e1a9a4a43052758872873162fce11380a9231a9d8378

See more details on using hashes here.

File details

Details for the file crosstab-0.0.15-py3-none-any.whl.

File metadata

  • Download URL: crosstab-0.0.15-py3-none-any.whl
  • Upload date:
  • Size: 34.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for crosstab-0.0.15-py3-none-any.whl
Algorithm Hash digest
SHA256 ae78b6209fe62c58d0b997a183fc47a0a6a3079c64c5588113c7c1c9c800db95
MD5 fd44b91794ea622972519537db00df9b
BLAKE2b-256 d16046c4b55c5c4fe26c2698f3c3c2a4dc5294d37bf2c670ca44a5ba1e314838

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page