Skip to main content

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

  • polars rather than pandas
  • Use of great_tables to display nicer tables.
  • In some cases, use of polars operations rather than numpy, though these are almost always identical.
  • Automatic determination of nonnormal columns and will display q1, median, q3 (whereas tableone defaults to showing mean even in these cases).
  • Specify number of bins for histograms using show_histograms=8; if show_histograms is set to True, the default is 10 bins (tableone defaults 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


Download files

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

Source Distribution

polartableone-0.1.1.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

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

polartableone-0.1.1-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

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

Hashes for polartableone-0.1.1.tar.gz
Algorithm Hash digest
SHA256 296f2d6ff455bd57e545a9e34963809a041a94f66b4544d850e949d146006611
MD5 91f106e1701a547459c0911fcbf7d93f
BLAKE2b-256 93767c149cf942c1235eb3eae6e1ad0f7b2d63b220b8b47bd69050ed10f9de8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for polartableone-0.1.1.tar.gz:

Publisher: release.yml on dcronkite/polartableone

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for polartableone-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 540a01184f5e69e4bc6c5e44ea58c46c64b6ab0e26e30887fafa320cf655c42e
MD5 e102f47e42e7277bf8bbfcedf423d052
BLAKE2b-256 bc785c6b8e2c64809f2339374604fe4c0cdbb73e7af20959869905f992396133

See more details on using hashes here.

Provenance

The following attestation bundles were made for polartableone-0.1.1-py3-none-any.whl:

Publisher: release.yml on dcronkite/polartableone

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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