Rearrange data from a normalized CSV format to a crosstabulated format, with styling.
Project description
crosstab
crosstab is a Python package that rearranges data from a normalized CSV format to a crosstabulated format, with styling.
Go from this:
To this:
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 output Excel 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file crosstab-0.0.13.tar.gz
.
File metadata
- Download URL: crosstab-0.0.13.tar.gz
- Upload date:
- Size: 49.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | da9e715831ddbcd15e592f7833e4dd25fd42d07f9878251fc739756de592a1b0 |
|
MD5 | f938ee39cf8b59ae63d83c7007827622 |
|
BLAKE2b-256 | 1ab567199d7aac2eb6a7981f5b1a77f19a2505569bcfaffdd883d26feee9ce4a |
File details
Details for the file crosstab-0.0.13-py3-none-any.whl
.
File metadata
- Download URL: crosstab-0.0.13-py3-none-any.whl
- Upload date:
- Size: 34.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48cebbf1c8ce9488f468fc2ea5fd514e4df83c3f4d43d8c85d836b39e5bb78af |
|
MD5 | a92def251ee1fcb825cad22068550ec0 |
|
BLAKE2b-256 | daac45625d45e510b4828a1c099c8acf68a1a1dbd35c4e5ca0eaf7c8a6350963 |