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.12.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 2 Python 3

File details

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

File metadata

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

File hashes

Hashes for tableone-0.1.12.tar.gz
Algorithm Hash digest
SHA256 e805121cef901e809b7ac1a54df727ab045517414d7c45a465216a2de402f215
MD5 7b477034731239c4d13851d54a48ef4c
BLAKE2b-256 bed9aab54745323da6f0f86dc4859fcb228f798c18df390753244c32a0b59194

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tableone-0.1.12-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 206854c81e2ff2b7932858dd90b64eac0f73628f9b45d1296cfb4bd7f13ff1d9
MD5 c5664ed4227eb25974db1a6b2377c4f0
BLAKE2b-256 52c8b686c843c2b9463fd00654b15e29d5c41b287ec1cb8f470a1ebae94bf1da

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