Skip to content

NKeleher/statsframe

Repository files navigation

statsframe

PyPI - Version PyPI - Python Version License Repo Status


Customizable data and model summaries in Python.

statsframe creates tables that provide descriptive statistics of numeric and categorical data.

The goal is to provide a simple -- yet customizable -- way to summarize data and models in Python.

statsframe is heavily inspired by modelsummary in R. The goal is not to replicate all that modelsummary does, but to provide a way of achieving similar results in Python.

In order to achieve this, statsframe builds on the polars library to produce tables that can be easily customized and exported to other formats.

Basic Usage

As an example of statsframe usage, the skim_frame function provides a summary of a DataFrame (either polars.DataFrame or pandas.DataFrame). The default summary statistics returned by statsframe.skim_frame() are unique values, percentage missing, mean, standard deviation, minimum, median, and maximum.

Where possible, statsframe will print a table to the console and return a polars DataFrame with the summary statistics. This allows for easy customization. For example, the polars.DataFrame with statistics from statsframe can be modified using the Great Tables package.

import polars as pl
import statsframe as sf

df = (
        pl.read_csv("https://vincentarelbundock.github.io/Rdatasets/csv/datasets/mtcars.csv")
          .drop("rownames")
    )

stats = sf.skim_frame(df)

Summary Statistics
Rows: 32, Columns: 11
┌──────┬────────────┬─────────────┬───────┬───────┬──────┬────────┬───────┐
│      ┆ Unique (#) ┆ Missing (%) ┆  Mean ┆    SD ┆  Min ┆ Median ┆   Max │
╞══════╪════════════╪═════════════╪═══════╪═══════╪══════╪════════╪═══════╡
│  mpg250.020.16.010.419.233.9 │
│  cyl30.06.21.84.06.08.0 │
│ disp270.0230.7123.971.1196.3472.0 │
│   hp220.0146.768.652.0123.0335.0 │
│ drat220.03.60.52.83.74.9 │
│   wt290.03.21.01.53.35.4 │
│ qsec300.017.81.814.517.722.9 │
│   vs20.00.40.50.00.01.0 │
│   am20.00.40.50.00.01.0 │
│ gear30.03.70.73.04.05.0 │
│ carb60.02.81.61.02.08.0 │
└──────┴────────────┴─────────────┴───────┴───────┴──────┴────────┴───────┘

We can achieve the same result above with a pandas DataFrame.

import pandas as pd
import statsframe as sf

trees_df = pd.read_csv(
    "https://vincentarelbundock.github.io/Rdatasets/csv/datasets/trees.csv"
).drop(columns=["rownames"])

trees_stats = sf.skim_frame(trees_df)

Summary Statistics
Rows: 31, Columns: 3
┌────────┬────────────┬─────────────┬──────┬──────┬──────┬────────┬──────┐
│        ┆ Unique (#) ┆ Missing (%) ┆ Mean ┆   SD ┆  Min ┆ Median ┆  Max │
╞════════╪════════════╪═════════════╪══════╪══════╪══════╪════════╪══════╡
│  Girth270.013.23.18.312.920.6 │
│ Height210.076.06.463.076.087.0 │
│ Volume300.030.216.410.224.277.0 │
└────────┴────────────┴─────────────┴──────┴──────┴──────┴────────┴──────┘

Contributing

If you encounter a bug, have usage questions, or want to share ideas to make the statsframe package more useful, please feel free to file an issue.

Code of Conduct

Please note that the statsframe project is released with a contributor code of conduct.

By participating in this project you agree to abide by its terms.

License

statsframe is licensed under the MIT license.

Governance

This project is primarily maintained by Niall Keleher. Contributions from other authors is welcome.

About

Customizable data and model summaries in Python.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published