Skip to main content

Describr is a Python library that provides a convenient way to generate descriptive statistics for datasets.

Project description

README.md

describr is a Python library that provides functionality for descriptive statistics and outlier detection in pandas DataFrames.

Installation

You can install describr using pip:

pip install describr

Example usage

import pandas as pd
import numpy as np
from describr import FindOutliers, DescriptiveStats

Create a sample dataframe

np.random.seed(0)
n = 500

data = {
    'MCID': ['MCID_' + str(i) for i in range(1, n + 1)],
    'Age': np.random.randint(18, 90, size=n),
    'Race': np.random.choice(['White', 'Black', 'Asian', 'Hispanic',''], size=n),
    'Educational_Status': np.random.choice(['High School', 'Bachelor', 'Master', 'PhD',''], size=n),
    'Gender': np.random.choice(['Male', 'Female', ''], size=n),
    'ER_COST': np.random.uniform(500, 5000, size=n),
    'ER_VISITS': np.random.randint(0, 10, size=n),
    'IP_COST': np.random.uniform(5000, 20000, size=n),
    'IP_ADMITS': np.random.randint(0, 5, size=n),
    'CHF': np.random.choice([0, 1], size=n),
    'COPD': np.random.choice([0, 1], size=n),
    'DM': np.random.choice([0, 1], size=n),
    'ASTHMA': np.random.choice([0, 1], size=n),
    'HYPERTENSION': np.random.choice([0, 1], size=n),
    'SCHIZOPHRENIA': np.random.choice([0, 1], size=n),
    'MOOD_DEPRESSED': np.random.choice([0, 1], size=n),
    'MOOD_BIPOLAR': np.random.choice([0, 1], size=n),
    'TREATMENT': np.random.choice(['Yes', 'No'], size=n)
}

df = pd.DataFrame(data)

Parameters

df: name of dataframe

id_col: Primary key of the dataframe; accepts string or integer or float.

group_col: A Column to group by, It must be a binary column. Strings or integers are acceptable.

positive_class: This is the response value for the primary outcome of interest. For instance, positive value for a Treatment cohort is 'Yes' or 1 otherwise 'No' or 0, respectively. Strings or integers are acceptable.

continuous_var_summary: User specifies measures of central tendency, only mean and median are acceptable. This parameter is case insensitive.

Example usage of FindOutliers Class

This returns a dataframe (outliers_flag_df) with outlier_flag column (outlier_flag =1: record contains one or more ouliers). Tukey's IQR method is used to detect outliers in the data

outliers_flag=FindOutliers(df=df, id_col='MCID', group_col='TREATMENT')
outliers_flag_df=outliers_flag.flag_outliers()

This example counts number of rows with outliers stratified by a defined grouping variable

outliers_flag.count_outliers()

This example removes all outliers

df2=outliers_flag.remove_outliers()
df2.shape

Example usage of DescriptiveStats Class

descriptive_stats = DescriptiveStats(df=df, id_col='MCID', group_col='TREATMENT', positive_class='Yes', continuous_var_summary='median')

Gets statistics for binary and categorical variables and returns a dataframe.

binary_stats_df = descriptive_stats.get_binary_stats()

Gets mean and standard deviation for continuous variables and returns a dataframe.

continuous_stats_mean_df = descriptive_stats.get_continuous_mean_stats()

Gets median and interquartile range for continuous variables and returns a dataframe.

continuous_stats_median_df = descriptive_stats.get_continuous_median_stats()

Computes summary statistics for binary and continuous variables based on defined measure of central tendency. Method returns a dataframe.

descriptive_stats.compute_descriptive_stats()
summary_stats = descriptive_stats.summary_stats()

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

describr-0.0.27.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

describr-0.0.27-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file describr-0.0.27.tar.gz.

File metadata

  • Download URL: describr-0.0.27.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for describr-0.0.27.tar.gz
Algorithm Hash digest
SHA256 4645e89ad4c7d14629221e21584f1d8f60495e4d0649490d86cb1d8c54d18aec
MD5 78360b4f7750db4f8389da25a442f0e8
BLAKE2b-256 48a6010d7fa058572ca31aa5e1b09c14bb44d38b19fc3f01b4a055dd80205e7d

See more details on using hashes here.

File details

Details for the file describr-0.0.27-py3-none-any.whl.

File metadata

  • Download URL: describr-0.0.27-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for describr-0.0.27-py3-none-any.whl
Algorithm Hash digest
SHA256 8c95d6fc19d396925b0586a2da085f81d3b11796f169e0d2870ed4a79598f175
MD5 315eeaaa1d99798cff492f316a9ccd22
BLAKE2b-256 1ec02cfd5977b8a72d9ecf6a8027e87e0c39c4a6fb6503cfa91764dd96fc162a

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