A polars-based implementation of the `tableone` library for generating summary statistics tables, often referred to as a 'Table 1'.
Project description
polartableone
A polars-based implementation of the tableone library for generating summary statistics tables, often referred to as a 'Table 1'.
Features
- Fast summary statistics for a 'Table 1' using polars
- Automatic detection of categorical, continuous, and nonnormal variables
- Support for stratified tables and p-values
- Beautiful table formatting via Great Tables
- Export to HTML, CSV, Excel, LaTeX, and many tabular formats
Differences with tableone Library
polarsrather thanpandas- Use of
great_tablesto display nicer tables. - In some cases, use of
polarsoperations rather thannumpy, though these are almost always identical. - Automatic determination of nonnormal columns and will display q1, median, q3 (whereas
tableonedefaults to showingmeaneven in these cases). - Specify number of bins for histograms using
show_histograms=8; ifshow_histogramsis set toTrue, the default is 10 bins (tableonedefaults to 8)
But I Prefer tableone
Great! Just convert your polars dataframe to pandas (df.to_pandas()) and then use tableone!
Installation
pip install polartableone
Usage
import polars as pl
from polartableone import TableOne
# load your data
df = pl.read_csv('tests/datasets/pn2012.csv')
# columns to summarize
columns = ['Age', 'SysABP', 'Height', 'Weight', 'ICU', 'death']
# columns containing categorical variables
categorical = ['ICU']
# columns containing categorical variables
continuous = ['Age', 'SysABP', 'Height', 'Weight']
# non-normal variables
nonnormal = ['Age']
# limit the binary variable "death" to a single row
limit = {"death": 1}
# set the order of the categorical variables
order = {"ICU": ["MICU", "SICU", "CSRU", "CCU"]}
# set decimal places for age to 0
decimals = {"Age": 0}
# optionally, a categorical variable for stratification
groupby = 'death'
# rename the death column
labels = {'death': 'Mortality'}
# display minimum and maximum for listed variables
min_max = ['Height']
table = TableOne(df, columns=columns, categorical=categorical, continuous=continuous,
groupby=groupby, nonnormal=nonnormal, rename=labels, label_suffix=True,
decimals=decimals, limit=limit, min_max=min_max, show_histograms=True,
dip_test=True, normal_test=True, tukey_test=True)
# Export to CSV
table.write_csv('table1.csv')
# Export to Great Tables object for further styling
gt_table = table.to_gt()
gt_table.show()
| Level | Missing | Overall | Histogram | 0 | 1 | |
|---|---|---|---|---|---|---|
| n | 1000 | 864 | 136 | |||
| Age, median [Q1,Q3] | 0 | 68 [53,79] | ▂▁▂▃▅▆▆▇▇█ | 66 [53,78] | 75 [62,83] | |
| SysABP, median [Q1,Q3] | 291 | 119.0 [102.0,137.0] | ▂▁▁▁▄█▇▅▂▁ | 119.0 [104.0,137.0] | 115.0 [90.0,136.0] | |
| Height, min – max | 475 | 13.0 – 406.4 | ▁▁▆▅▅▆█▅▁▁ | 13.0 – 406.4 | 144.8 – 188.0 | |
| Weight, median [Q1,Q3] | 302 | 80.0 [66.1,96.0] | ▂▅▇█▆▃▃▂▁▁ | 80.5 [66.3,96.0] | 77.0 [64.8,96.7] | |
| ICU, n (%) | CCU | 162 (16.2) | 137 (15.9) | 25 (18.4) | ||
| ICU, n (%) | CSRU | 202 (20.2) | 194 (22.5) | 8 (5.9) | ||
| ICU, n (%) | MICU | 380 (38.0) | 318 (36.8) | 62 (45.6) | ||
| ICU, n (%) | SICU | 256 (25.6) | 215 (24.9) | 41 (30.1) |
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polartableone-0.1.1.tar.gz.
File metadata
- Download URL: polartableone-0.1.1.tar.gz
- Upload date:
- Size: 17.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
296f2d6ff455bd57e545a9e34963809a041a94f66b4544d850e949d146006611
|
|
| MD5 |
91f106e1701a547459c0911fcbf7d93f
|
|
| BLAKE2b-256 |
93767c149cf942c1235eb3eae6e1ad0f7b2d63b220b8b47bd69050ed10f9de8f
|
Provenance
The following attestation bundles were made for polartableone-0.1.1.tar.gz:
Publisher:
release.yml on dcronkite/polartableone
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polartableone-0.1.1.tar.gz -
Subject digest:
296f2d6ff455bd57e545a9e34963809a041a94f66b4544d850e949d146006611 - Sigstore transparency entry: 820642025
- Sigstore integration time:
-
Permalink:
dcronkite/polartableone@12051fbb780df4d84b3ef45a39886eb1c48142f3 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/dcronkite
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@12051fbb780df4d84b3ef45a39886eb1c48142f3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file polartableone-0.1.1-py3-none-any.whl.
File metadata
- Download URL: polartableone-0.1.1-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
540a01184f5e69e4bc6c5e44ea58c46c64b6ab0e26e30887fafa320cf655c42e
|
|
| MD5 |
e102f47e42e7277bf8bbfcedf423d052
|
|
| BLAKE2b-256 |
bc785c6b8e2c64809f2339374604fe4c0cdbb73e7af20959869905f992396133
|
Provenance
The following attestation bundles were made for polartableone-0.1.1-py3-none-any.whl:
Publisher:
release.yml on dcronkite/polartableone
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polartableone-0.1.1-py3-none-any.whl -
Subject digest:
540a01184f5e69e4bc6c5e44ea58c46c64b6ab0e26e30887fafa320cf655c42e - Sigstore transparency entry: 820642031
- Sigstore integration time:
-
Permalink:
dcronkite/polartableone@12051fbb780df4d84b3ef45a39886eb1c48142f3 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/dcronkite
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@12051fbb780df4d84b3ef45a39886eb1c48142f3 -
Trigger Event:
push
-
Statement type: