A utility package for data visualization and statistical analysis with Matplotlib and Seaborn
Project description
Data Visualiser Package
A Python utility package for data visualization and statistical analysis with Matplotlib and Seaborn. This package provides a simple interface to create common visualizations and statistical tables for exploratory data analysis and reporting.
Installation
pip install data-visualiser-package
Features
- Create count plots and distribution plots
- Generate stratified visualizations by categorical variables
- Compute and display statistical tables for numerical and categorical variables
- Save plots and tables to disk (including LaTeX export)
- Handling of missing values
Quick Start
import pandas as pd
from data_visualiser_package import DataVisualiser
# Create a DataVisualiser instance
dv = DataVisualiser(
record_unit_name="patient", # What a single record represents
figures_dirpath="./figures", # Where to save figures
tables_dirpath="./tables", # Where to save tables
create_dirs=True # Create directories if they don't exist
)
# Load your data
df = pd.read_csv("your_data.csv")
# Create a count plot
fig, ax = dv.get_count_plot(
var="diagnosis", # Categorical variable to plot
df=df, # DataFrame containing the data
show_nan=True, # Show NaN values as a separate category
save_fig=True # Save the figure to disk
)
# Create a distribution plot
fig, ax = dv.get_dist_plot(
var="age", # Numerical variable to plot
df=df, # DataFrame containing the data
save_fig=True # Save the figure to disk
)
# Generate statistics tables
stats_df = dv.get_count_stats_df(
var="diagnosis", # Categorical variable to analyze
df=df, # DataFrame containing the data
save_table=True # Save the table to disk as LaTeX
)
# Create stratified visualizations
fg = dv.get_dist_stratified_plot(
var="age", # Numerical variable to plot
df=df, # DataFrame containing the data
col="gender", # Categorical variable to stratify by
save_fig=True # Save the figure to disk
)
Example
Here's a complete example of how to use the DataVisualiser class:
import pandas as pd
import numpy as np
from data_visualiser_package import DataVisualiser
# Create a sample dataset
np.random.seed(42)
n = 1000
# Generate sample data
data = {
'age': np.random.normal(50, 15, n),
'gender': np.random.choice(['Male', 'Female'], n),
'diagnosis': np.random.choice(['Healthy', 'Condition A', 'Condition B', None], n, p=[0.6, 0.2, 0.15, 0.05]),
'heart_rate': np.random.normal(80, 10, n),
'blood_pressure': np.random.normal(120, 15, n)
}
# Create a DataFrame
df = pd.DataFrame(data)
# Initialize the DataVisualiser
dv = DataVisualiser(
record_unit_name="patient",
figures_dirpath="./output/figures",
tables_dirpath="./output/tables",
create_dirs=True
)
# Create plots
dv.get_count_plot('gender', df, save_fig=True)
dv.get_count_plot('diagnosis', df, save_fig=True)
# Create stratified count plots
dv.get_count_stratified_plot('diagnosis', df, col='gender', save_fig=True)
# Distribution plots
dv.get_dist_plot('age', df, save_fig=True)
dv.get_dist_stratified_plot('age', df, col='gender', save_fig=True)
dv.get_dist_hued_plot('age', df, hue='gender', save_fig=True)
# Generate statistics tables
dv.get_count_stats_df('diagnosis', df, save_table=True)
dv.get_dist_stats_df('age', df, save_table=True)
dv.get_dist_stratified_stats_df('age', df, col='gender', save_table=True)
print("All visualizations and tables have been generated successfully!")
API Reference
DataVisualiser Class
class DataVisualiser(
record_unit_name="patient",
figures_dirpath=None,
tables_dirpath=None,
create_dirs=False
)
Count Visualizations
get_count_plot(var, df, show_nan=True, save_fig=False, plot_kwargs={}, xlabels_rotation=None, forced_order=None)get_count_stratified_plot(var, df, col="gender", show_nan=True, show_nan_col=True, save_fig=False, col_wrap=3, plot_kwargs={}, xlabels_rotation=None, forced_order=None, forced_order_col=None)get_count_stats_df(var, df, show_nan=True, save_table=False, percentage=True, add_total=False, round_n_digits=1, forced_order=None)get_count_stratified_stats_df(var, df, col="gender", show_nan=True, show_nan_col=True, save_table=False, percentage=True, round_n_digits=1, forced_order=None, forced_order_col=None)
Distribution Visualizations
get_dist_plot(var, df, save_fig=False, plot_kwargs={"kde": True}, xlabels_rotation=None)get_dist_stratified_plot(var, df, col="gender", show_nan_col=True, save_fig=False, col_wrap=3, plot_kwargs={"kde": True}, xlabels_rotation=None, forced_order_col=None)get_dist_hued_plot(var, df, hue="gender", show_nan_col=True, save_fig=False, plot_kwargs={"kde": True}, xlabels_rotation=None, forced_order_col=None)get_dist_stats_df(var, df, save_table=False)get_dist_stratified_stats_df(var, df, col="gender", show_nan_col=True, save_table=False, forced_order_col=None)
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file data_visualiser_package-0.1.0.tar.gz.
File metadata
- Download URL: data_visualiser_package-0.1.0.tar.gz
- Upload date:
- Size: 27.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22e11021406807f142fa812d646f1ef1956cf07f980cfd1a6c0d0d103bceed70
|
|
| MD5 |
99dc73ebad707faa57263cac42bcf87a
|
|
| BLAKE2b-256 |
5e3fbd376fb3a9642e3729968d754b11e22f80168fa0b266af29672752662d07
|
File details
Details for the file data_visualiser_package-0.1.0-py3-none-any.whl.
File metadata
- Download URL: data_visualiser_package-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
270e6c5ff1426c47ff0939b78a0ca69a5b38c1c9b77370fffdef40e4424ed2c7
|
|
| MD5 |
b77f2ccba2259d9a5faa04ecc74a780f
|
|
| BLAKE2b-256 |
7672d0dce6699fcd6448f09e5e06869a5f2b42f145b231c311350eeb24d50f60
|