A Python package for beautifying statistical outputs into clean tables
Project description
Stable
A Python package for beautifying statistical outputs from scipy, statsmodels, and other libraries into clean, publication-ready tables.
Features
- Automatic Detection: Recognizes common statistical tests (t-tests, ANOVA, chi-square, regression, etc.)
- Multiple Export Formats: Markdown, Excel, HTML, and pandas DataFrame
- Pretty Formatting: Rounded decimals, significance stars, confidence intervals
- Flexible Input: Works with scipy.stats and statsmodels results
- Easy to Use: Simple API with methods like
.to_markdown(),.to_excel()
Installation
From PyPI (recommended)
pip install stable-stats
From source
git clone https://github.com/Chris-R030307/StaTable.git
cd StaTable
pip install -e .
Development installation
git clone https://github.com/Chris-R030307/StaTable.git
cd StaTable
pip install -e ".[dev,test]"
Dependencies
The package requires:
- Python 3.8+
- numpy >= 1.19.0
- pandas >= 1.3.0
- scipy >= 1.7.0
- statsmodels >= 0.12.0
- openpyxl >= 3.0.0 (for Excel export)
Quick Start
from scipy import stats
from stable import Stable
# Run a statistical test
result = stats.ttest_ind(group1, group2)
# Beautify the results
table = Stable(result)
# Export to different formats
print(table.to_markdown()) # Pretty table in console
table.to_excel("results.xlsx") # Export to Excel
html_output = table.to_html() # Get HTML string
Examples
T-test
import numpy as np
from scipy import stats
from stable import Stable
# Generate sample data
np.random.seed(42)
group1 = np.random.normal(100, 15, 30)
group2 = np.random.normal(110, 15, 30)
# Run t-test
result = stats.ttest_ind(group1, group2)
# Beautify
stable = Stable(result)
print(stable.to_markdown())
Output:
## Independent t-test
**Sample Size:** 30
## Results
| Statistic | Value | p-value | Significance |
|-----------|-------|---------|--------------|
| Test Statistic | -2.108 | 0.039* | * |
Effect Size: -2.108
ANOVA
# Generate data for 3 groups
group_a = np.random.normal(50, 10, 25)
group_b = np.random.normal(55, 10, 25)
group_c = np.random.normal(60, 10, 25)
# Run ANOVA
result = stats.f_oneway(group_a, group_b, group_c)
# Beautify
stable = Stable(result)
print(stable.to_markdown())
Linear Regression
import pandas as pd
import statsmodels.api as sm
from statsmodels.formula.api import ols
# Generate sample data
x = np.random.normal(0, 1, 100)
y = 2 * x + np.random.normal(0, 0.5, 100)
df = pd.DataFrame({'x': x, 'y': y})
# Run regression
model = ols('y ~ x', data=df).fit()
# Beautify
stable = Stable(model)
print(stable.to_markdown())
Direct Analysis Methods
# Direct t-test
stable = Stable.from_ttest(group1, group2)
# Direct ANOVA
stable = Stable.from_anova(group_a, group_b, group_c)
# Direct chi-square
observed = [20, 30, 25, 25]
expected = [25, 25, 25, 25]
stable = Stable.from_chi2(observed, expected)
Supported Statistical Tests
Scipy.stats
- t-tests (independent, paired, one-sample)
- ANOVA (one-way)
- Chi-square tests
- Kolmogorov-Smirnov tests
- Mann-Whitney U test
- Wilcoxon signed-rank test
- Kruskal-Wallis test
- Friedman test
Statsmodels
- Linear regression
- ANOVA
- t-tests
- F-tests
- Contrast tests
Export Formats
Markdown
markdown_output = stable.to_markdown(title="My Analysis")
print(markdown_output)
Excel
stable.to_excel("results.xlsx", sheet_name="Analysis")
HTML
html_output = stable.to_html(title="My Analysis", include_css=True)
Pandas DataFrame
df = stable.to_dataframe()
API Reference
Stable Class
Methods
to_markdown(title=None): Export to Markdown formatto_excel(filename, sheet_name="Statistical Results"): Export to Excelto_html(title=None, include_css=True): Export to HTMLto_dataframe(): Export to pandas DataFramesummary(): Get brief summary of resultsis_supported(): Check if result type is supported
Properties
get_test_name(): Get human-readable test nameget_statistic(): Get test statistic(s)get_p_value(): Get p-value(s)get_effect_size(): Get effect size(s)get_confidence_interval(): Get confidence intervalget_sample_size(): Get sample size informationget_degrees_of_freedom(): Get degrees of freedomget_coefficients(): Get coefficient information (regression)get_model_info(): Get model information (regression)
Class Methods
Stable.from_ttest(group1, group2, **kwargs): Direct t-testStable.from_anova(*groups, **kwargs): Direct ANOVAStable.from_chi2(observed, expected=None, **kwargs): Direct chi-squareStable.from_regression(model_result): From regression result
Package Structure
stable/
├── __init__.py # Main package interface
├── core.py # Core Stable class
├── utils.py # Helper functions
├── adapters/ # Input adapters
│ ├── scipy_adapter.py # Scipy.stats adapter
│ └── statsmodels_adapter.py # Statsmodels adapter
└── exporters/ # Output exporters
├── markdown.py # Markdown exporter
├── excel.py # Excel exporter
└── html.py # HTML exporter
Requirements
- Python 3.7+
- numpy >= 1.19.0
- pandas >= 1.3.0
- scipy >= 1.7.0
- statsmodels >= 0.12.0
- openpyxl >= 3.0.0 (for Excel export)
Development
Setup Development Environment
git clone <repository-url>
cd stable
pip install -e ".[dev]"
Run Tests
pytest
Run Example
python example_usage.py
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
MIT License - see LICENSE file for details.
Future Features
- Support for more statistical libraries (pingouin, sklearn)
- Interactive tables (Plotly dashboards)
- Custom templates (APA style, clinical reports)
- LaTeX export
- More effect size calculations
- Power analysis integration
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
stable_stats-0.1.4.tar.gz
(26.9 kB
view details)
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 stable_stats-0.1.4.tar.gz.
File metadata
- Download URL: stable_stats-0.1.4.tar.gz
- Upload date:
- Size: 26.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c90c649c5eb41c310d4340d1cdfeb4d3e64e48fe0ade6d73b2d94f2db502e4c
|
|
| MD5 |
b9b1235788a1b40c6707371a6602193a
|
|
| BLAKE2b-256 |
b2de162ebf60e09d7ee305157a99ec3b8990ebd2682e43b4278f89a4c8583e65
|
File details
Details for the file stable_stats-0.1.4-py3-none-any.whl.
File metadata
- Download URL: stable_stats-0.1.4-py3-none-any.whl
- Upload date:
- Size: 22.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9b1e520a96c748babf97e75bc9d40babdf8b454242afa9c2f030d1363ab924d
|
|
| MD5 |
3641747bf0828372fef3bcdc7966c91e
|
|
| BLAKE2b-256 |
a7b6df5b976ada831a2968a1d0af69d25a28cf74856560772bb20ad7955b5158
|