Skip to main content

Table One

Project description

https://travis-ci.org/tompollard/tableone.svg?branch=master

tableone is a package for researchers who need to create Table 1, summary statistics for a patient population. It was inspired by the R package of the same name by Kazuki Yoshida and Justin Bohn. A demo Jupyter Notebook is available at: https://github.com/tompollard/tableone/blob/master/tableone.ipynb

Installation

The distribution is hosted on PyPI and directly installable via pip without needing to clone or download this repository. To install the package from PyPI, run the following command in your terminal:

pip install tableone

Usage

To follow…

Example

  1. Import libraries:

    from tableone import TableOne
    import pandas as pd
  2. Load sample data into a pandas dataframe:

    url="https://raw.githubusercontent.com/tompollard/data/master/primary-biliary-cirrhosis/pbc.csv"
    data=pd.read_csv(url)
  3. List of columns containing continuous variables:

    convars = ['time','age','ascites','hepato','spiders','bili']
  4. List of columns containing categorical variables:

    catvars = ['status','edema','stage']
  5. Optionally, a categorical variable for stratification and a list of non-normal variables:

    strat = 'trt'
    nonnormal = ['bili']
  1. Create an instance of TableOne with the input arguments:

    mytable = TableOne(data, convars, catvars, strat, nonnormal)
  2. Type the name of the instance in an interpreter:

    mytable
  3. …which prints the following table to screen:

    Stratified by trt
                          1.0                2.0
    --------------------  -----------------  -----------------
    n                     158                154
    time (mean (std))     2015.62 (1094.12)  1996.86 (1155.93)
    age (mean (std))      51.42 (11.01)      48.58 (9.96)
    ascites (mean (std))  0.09 (0.29)        0.06 (0.25)
    hepato (mean (std))   0.46 (0.50)        0.56 (0.50)
    spiders (mean (std))  0.28 (0.45)        0.29 (0.46)
    bili (median [IQR])   1.40 [0.80,3.20]   1.30 [0.72,3.60]
    status (n (%))
    0                     83.00 (52.53)      85.00 (55.19)
    1                     10.00 (6.33)       9.00 (5.84)
    2                     65.00 (41.14)      60.00 (38.96)
    edema (n (%))
    0.0                   132.00 (83.54)     131.00 (85.06)
    0.5                   16.00 (10.13)      13.00 (8.44)
    1.0                   10.00 (6.33)       10.00 (6.49)
    stage (n (%))
    1.0                   12.00 (7.59)       4.00 (2.60)
    2.0                   35.00 (22.15)      32.00 (20.78)
    3.0                   56.00 (35.44)      64.00 (41.56)
    4.0                   55.00 (34.81)      54.00 (35.06)
  1. Tables can be exported to file in various formats, including LaTeX, Markdown, CSV, and HTML. Files are exported by calling the to_format methods. For example, mytable can be exported to a CSV named ‘mytable.csv’ with the following command:

    mytable.to_csv('mytable.csv')

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

tableone-0.1.11.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

tableone-0.1.11-py2.py3-none-any.whl (7.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file tableone-0.1.11.tar.gz.

File metadata

  • Download URL: tableone-0.1.11.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for tableone-0.1.11.tar.gz
Algorithm Hash digest
SHA256 affe8e8677250dba296b8fd66c77ad60ccc6d11044b64c1789f142305f526ea2
MD5 0103800af6f2265a75b7ec2a4e124380
BLAKE2b-256 8d5cbb9de0a9ce75580b15140240efcaa9daf1f3e5c6702e435e1d4a20cd7214

See more details on using hashes here.

File details

Details for the file tableone-0.1.11-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for tableone-0.1.11-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 23b05e077c28cc612099198e11d9c82bf72811e9362359c5cfa9dca54e101294
MD5 4b7e86952cb4b602136d9822db2d6f47
BLAKE2b-256 ba82aa07e5eef8765339a613ac92684c8c2756a6ca2fafd76bd5b4d68933ad6e

See more details on using hashes here.

Supported by

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