Thanks to visit codestin.com
Credit goes to github.com

Skip to content

aeturrell/skimpy

Repository files navigation

Skimpy

A light weight tool for creating summary statistics from dataframes. png

PyPI Status Python Version License Read the documentation at https://aeturrell.github.io/skimpy/ Tests Codecov Downloads pre-commit Black Google Colab

Linux macOS Windows

Soure

skimpy is a light weight tool that provides summary statistics about variables in pandas or Polars data frames within the console or your interactive Python window. Think of it as a super-charged version of pandas' df.describe(). You can find the documentation here.

Quickstart

skim a Pandas dataframe and produce summary statistics within the console using:

from skimpy import skim

skim(df)

where df is a dataframe. Alternatively, use skim_polars() on Polars dataframes.

If you need to a dataset to try skimpy out on, you can use the built-in test Pandas data frame:

from skimpy import skim, generate_test_data

df = generate_test_data()
skim(df)
╭──────────────────────────────────────────────── skimpy summary ─────────────────────────────────────────────────╮
│          Data Summary                Data Types               Categories                                        │
│ ┏━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓ ┏━━━━━━━━━━━━━┳━━━━━━━┓ ┏━━━━━━━━━━━━━━━━━━━━━━━┓                                │
│ ┃ dataframe          Values ┃ ┃ Column Type  Count ┃ ┃ Categorical Variables ┃                                │
│ ┡━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩ ┡━━━━━━━━━━━━━╇━━━━━━━┩ ┡━━━━━━━━━━━━━━━━━━━━━━━┩                                │
│ │ Number of rows    │ 1000   │ │ float64     │ 3     │ │ class                 │                                │
│ │ Number of columns │ 13     │ │ category    │ 2     │ │ location              │                                │
│ └───────────────────┴────────┘ │ datetime64  │ 2     │ └───────────────────────┘                                │
│                                │ object      │ 2     │                                                          │
│                                │ int64       │ 1     │                                                          │
│                                │ bool        │ 1     │                                                          │
│                                │ string      │ 1     │                                                          │
│                                │ timedelta64 │ 1     │                                                          │
│                                └─────────────┴───────┘                                                          │
│                                                     number                                                      │
│ ┏━━━━━━━━━━━━━━━━┳━━━━━━┳━━━━━━━━┳━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━┓  │
│ ┃ column_name     NA    NA %    mean     sd     p0         p25     p50        p75    p100   hist   ┃  │
│ ┡━━━━━━━━━━━━━━━━╇━━━━━━╇━━━━━━━━╇━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━┩  │
│ │ length           0     0    0.5 0.36  1.6e-06  0.13      0.5 0.86    1▇▃▃▃▅▇ │  │
│ │ width            0     0      2  1.9   0.0021   0.6      1.5    3   14 ▇▃▁   │  │
│ │ depth            0     0     10  3.2        2     8       10   12   20▁▃▇▆▃▁ │  │
│ │ rnd            118  11.8  -0.02    1     -2.8 -0.74 -0.00077 0.66  3.7▁▅▇▅▁  │  │
│ └────────────────┴──────┴────────┴─────────┴───────┴───────────┴────────┴───────────┴───────┴───────┴────────┘  │
│                                                    category                                                     │
│ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┓  │
│ ┃ column_name                       NA         NA %            ordered                unique             ┃  │
│ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━┩  │
│ │ class                                   0             0False                                 2 │  │
│ │ location                                1           0.1False                                 5 │  │
│ └──────────────────────────────────┴───────────┴────────────────┴───────────────────────┴────────────────────┘  │
│                                                      bool                                                       │
│ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓  │
│ ┃ column_name                         true             true rate                      hist                ┃  │
│ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩  │
│ │ booly_col                                     516                         0.52      ▇    ▇        │  │
│ └────────────────────────────────────┴─────────────────┴───────────────────────────────┴─────────────────────┘  │
│                                                    datetime                                                     │
│ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓  │
│ ┃ column_name                   NA     NA %      first               last               frequency       ┃  │
│ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩  │
│ │ datetime                        0       0    2018-01-31       2101-04-30    M               │  │
│ │ datetime_no_freq                3     0.3    1992-01-05       2023-03-04    None            │  │
│ └──────────────────────────────┴───────┴──────────┴────────────────────┴───────────────────┴─────────────────┘  │
│                                            <class 'datetime.date'>                                              │
│ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓  │
│ ┃ column_name                       NA     NA %      first             last              frequency      ┃  │
│ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩  │
│ │ datetime.date                       0       02018-01-31      2101-04-30      M              │  │
│ │ datetime.date_no_freq               0       01992-01-05      2023-03-04      None           │  │
│ └──────────────────────────────────┴───────┴──────────┴──────────────────┴──────────────────┴────────────────┘  │
│                                                  timedelta64                                                    │
│ ┏━━━━━━━━━━━━━━━━━┳━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┓  │
│ ┃ column_name      NA    NA %    mean                        median                max                  ┃  │
│ ┡━━━━━━━━━━━━━━━━━╇━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━┩  │
│ │ time diff         5   0.5 8 days 00:05:47.336683417     0 days 00:00:00    26 days 00:00:00 │  │
│ └─────────────────┴──────┴────────┴────────────────────────────┴──────────────────────┴──────────────────────┘  │
│                                                     string                                                      │
│ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┓  │
│ ┃ column_name                NA       NA %        words per row                 total words              ┃  │
│ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━┩  │
│ │ text                           6       0.6                         5.8                    5761 │  │
│ └───────────────────────────┴─────────┴────────────┴──────────────────────────────┴──────────────────────────┘  │
╰────────────────────────────────────────────────────── End ──────────────────────────────────────────────────────╯

It is recommended that you set your datatypes before using skimpy (for example converting any text columns to pandas string datatype), as this will produce richer statistical summaries. However, the skim function will try and guess what the datatypes of your columns are.

skimpy also comes with a clean_columns function as a convenience (with thanks to the dataprep package). This slugifies column names. For example,

import pandas as pd
from rich import print
from skimpy import clean_columns

columns = [
    "bs lncs;n edbn ",
    "Nín hǎo. Wǒ shì zhōng guó rén",
    "___This is a test___",
    "ÜBER Über German Umlaut",
]
messy_df = pd.DataFrame(columns=columns, index=[0], data=[range(len(columns))])
print("Column names:")
print(list(messy_df.columns))
Column names:
['bs lncs;n edbn ', 'Nín hǎo. Wǒ shì zhōng guó rén', '___This is a test___', 'ÜBER Über German Umlaut']

Now let's clean these—by default what we get back is in snake case:

clean_df = clean_columns(messy_df)
print(list(clean_df.columns))
['bs_lncs_n_edbn', 'nin_hao_wo_shi_zhong_guo_ren', 'this_is_a_test', 'uber_uber_german_umlaut']

Other naming conventions are available, for example camel case:

clean_df = clean_columns(messy_df, case="camel")
print(list(clean_df.columns))
['bsLncsNEdbn', 'ninHaoWoShiZhongGuoRen', 'thisIsATest', 'uberUberGermanUmlaut']

Requirements

You can find a full list of requirements in the pyproject.toml file. The main requirements are:

import toml
from pathlib import Path

config = toml.load(Path("../pyproject.toml"))
dict_main_deps = config["tool"]["poetry"]["dependencies"]
for key, value in dict_main_deps.items():
    print(f"{key} {value}")
python >=3.8,<4.0.0
click ^8.1.6
rich >=10.9,<14.0
pandas ^2.0.3
Pygments ^2.10.0
jupyter ^1.0.0
ipykernel ^6.7.0
numpy ^1.22.2
typeguard 4.1.4
polars {'version': '^0.19.0', 'optional': True}
pyarrow {'version': '^13.0.0', 'optional': True}

You can try this package out right now in your browser using this Google Colab notebook (requires a Google account). Note that the Google Colab notebook uses the latest package released on PyPI (rather than the development release).

Installation

You can install the latest release of skimpy via pip from PyPI:

$ pip install skimpy

To install the development version from git, use:

$ pip install git+https://github.com/aeturrell/skimpy.git

For development, see {ref}contributing.

Use

This package is mostly designed to be used within an interactive console session or Jupyter notebook

from skimpy import skim

skim(df)

However, you can also use it on the command line:

$ skimpy file.csv

Features

  • Support for boolean, numeric, datetime, string, and category datatypes
  • Command line interface in addition to interactive console functionality
  • Light weight, with results printed to terminal using the rich package.
  • Rounds numerical output to 2 significant figures

Contributing

Contributions are very welcome. To learn more, see the page on {ref}contributing.

Note that you will need Make installed to build the docs automatically

License

Distributed under the terms of the MIT license, skimpy is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Credits

This project was generated from @cjolowicz's Hypermodern Python Cookiecutter template.

skimpy was inspired by the R package skimr and by exploratory Python packages including pandas_profiling and dataprep, from which the clean_columns function comes.

The package is built with poetry, while the documentation is built with Jupyter Book. Tests are run with nox.

Using skimpy in your paper? Let us know by raising an issue beginning with "citation" and we'll add it to this page.

About

skimpy is a light weight tool that provides summary statistics about variables in data frames within the console.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 8