data-visualiser-package 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data_visualiser_package-0.1.0/.github/workflows/python-package.yml +61 -0
- data_visualiser_package-0.1.0/.gitignore +51 -0
- data_visualiser_package-0.1.0/.python-version +1 -0
- data_visualiser_package-0.1.0/CHANGELOG.md +16 -0
- data_visualiser_package-0.1.0/LICENSE +21 -0
- data_visualiser_package-0.1.0/MANIFEST.in +12 -0
- data_visualiser_package-0.1.0/PKG-INFO +181 -0
- data_visualiser_package-0.1.0/PYPI_PUBLISH.md +70 -0
- data_visualiser_package-0.1.0/README.md +154 -0
- data_visualiser_package-0.1.0/examples/demo.py +95 -0
- data_visualiser_package-0.1.0/pyproject.toml +37 -0
- data_visualiser_package-0.1.0/pytest.ini +5 -0
- data_visualiser_package-0.1.0/requirements-dev.txt +8 -0
- data_visualiser_package-0.1.0/requirements.txt +5 -0
- data_visualiser_package-0.1.0/setup.py +45 -0
- data_visualiser_package-0.1.0/src/data_visualiser_package/__init__.py +12 -0
- data_visualiser_package-0.1.0/src/data_visualiser_package/data_visualiser.py +643 -0
- data_visualiser_package-0.1.0/src/data_visualiser_package/export_latex_tables.py +102 -0
- data_visualiser_package-0.1.0/src/data_visualiser_package/py.typed +0 -0
- data_visualiser_package-0.1.0/tests/test_data_visualiser.py +100 -0
- data_visualiser_package-0.1.0/uv.lock +298 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
name: Python Package
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
tags:
|
|
7
|
+
- 'v*'
|
|
8
|
+
pull_request:
|
|
9
|
+
branches: [ main ]
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
strategy:
|
|
15
|
+
matrix:
|
|
16
|
+
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v3
|
|
20
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
21
|
+
uses: actions/setup-python@v4
|
|
22
|
+
with:
|
|
23
|
+
python-version: ${{ matrix.python-version }}
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: |
|
|
26
|
+
python -m pip install --upgrade pip
|
|
27
|
+
python -m pip install flake8 pytest
|
|
28
|
+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
|
29
|
+
python -m pip install -e .
|
|
30
|
+
- name: Lint with flake8
|
|
31
|
+
run: |
|
|
32
|
+
# stop the build if there are Python syntax errors or undefined names
|
|
33
|
+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
|
34
|
+
# exit-zero treats all errors as warnings
|
|
35
|
+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics
|
|
36
|
+
- name: Test with pytest
|
|
37
|
+
run: |
|
|
38
|
+
pytest
|
|
39
|
+
|
|
40
|
+
deploy:
|
|
41
|
+
needs: test
|
|
42
|
+
runs-on: ubuntu-latest
|
|
43
|
+
if: startsWith(github.ref, 'refs/tags/')
|
|
44
|
+
|
|
45
|
+
steps:
|
|
46
|
+
- uses: actions/checkout@v3
|
|
47
|
+
- name: Set up Python
|
|
48
|
+
uses: actions/setup-python@v4
|
|
49
|
+
with:
|
|
50
|
+
python-version: '3.9'
|
|
51
|
+
- name: Install dependencies
|
|
52
|
+
run: |
|
|
53
|
+
python -m pip install --upgrade pip
|
|
54
|
+
pip install build twine
|
|
55
|
+
- name: Build and publish
|
|
56
|
+
env:
|
|
57
|
+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
|
|
58
|
+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
|
|
59
|
+
run: |
|
|
60
|
+
python -m build
|
|
61
|
+
twine upload dist/*
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Python-generated files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
build/
|
|
6
|
+
dist/
|
|
7
|
+
wheels/
|
|
8
|
+
*.egg-info/
|
|
9
|
+
*.egg
|
|
10
|
+
|
|
11
|
+
# Virtual environments
|
|
12
|
+
.venv/
|
|
13
|
+
venv/
|
|
14
|
+
ENV/
|
|
15
|
+
env/
|
|
16
|
+
|
|
17
|
+
# Distribution / packaging
|
|
18
|
+
.Python
|
|
19
|
+
downloads/
|
|
20
|
+
develop-eggs/
|
|
21
|
+
.eggs/
|
|
22
|
+
sdist/
|
|
23
|
+
var/
|
|
24
|
+
.installed.cfg
|
|
25
|
+
MANIFEST
|
|
26
|
+
|
|
27
|
+
# IDE files
|
|
28
|
+
.idea/
|
|
29
|
+
.vscode/
|
|
30
|
+
*.swp
|
|
31
|
+
*.swo
|
|
32
|
+
|
|
33
|
+
# Output directories
|
|
34
|
+
figures/
|
|
35
|
+
tables/
|
|
36
|
+
demo_output/
|
|
37
|
+
|
|
38
|
+
# Jupyter Notebook
|
|
39
|
+
.ipynb_checkpoints
|
|
40
|
+
|
|
41
|
+
# Environment variables
|
|
42
|
+
.env
|
|
43
|
+
.env.*
|
|
44
|
+
|
|
45
|
+
# Logs
|
|
46
|
+
*.log
|
|
47
|
+
|
|
48
|
+
# OS specific files
|
|
49
|
+
.DS_Store
|
|
50
|
+
Thumbs.db
|
|
51
|
+
desktop.ini
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.13
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the Data Visualiser Package will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2025-05-14
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release of the DataVisualiser package
|
|
12
|
+
- Core functionality for data visualization and statistical analysis
|
|
13
|
+
- Support for count plots and distribution plots
|
|
14
|
+
- Support for stratified visualizations
|
|
15
|
+
- LaTeX table export functionality
|
|
16
|
+
- Comprehensive documentation and examples
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Jonathan Doenz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: data-visualiser-package
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A utility package for data visualization and statistical analysis with Matplotlib and Seaborn
|
|
5
|
+
Project-URL: Homepage, https://github.com/jonathan-doenz/data-visualiser-package
|
|
6
|
+
Project-URL: Bug Tracker, https://github.com/jonathan-doenz/data-visualiser-package/issues
|
|
7
|
+
Author-email: jonathan-doenz <jonathan.doenz@gmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
21
|
+
Requires-Python: >=3.7
|
|
22
|
+
Requires-Dist: matplotlib>=3.3.0
|
|
23
|
+
Requires-Dist: numpy>=1.19.0
|
|
24
|
+
Requires-Dist: pandas>=1.0.0
|
|
25
|
+
Requires-Dist: seaborn>=0.11.0
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# Data Visualiser Package
|
|
29
|
+
|
|
30
|
+
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.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install data-visualiser-package
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- Create count plots and distribution plots
|
|
41
|
+
- Generate stratified visualizations by categorical variables
|
|
42
|
+
- Compute and display statistical tables for numerical and categorical variables
|
|
43
|
+
- Save plots and tables to disk (including LaTeX export)
|
|
44
|
+
- Handling of missing values
|
|
45
|
+
|
|
46
|
+
## Quick Start
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import pandas as pd
|
|
50
|
+
from data_visualiser_package import DataVisualiser
|
|
51
|
+
|
|
52
|
+
# Create a DataVisualiser instance
|
|
53
|
+
dv = DataVisualiser(
|
|
54
|
+
record_unit_name="patient", # What a single record represents
|
|
55
|
+
figures_dirpath="./figures", # Where to save figures
|
|
56
|
+
tables_dirpath="./tables", # Where to save tables
|
|
57
|
+
create_dirs=True # Create directories if they don't exist
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
# Load your data
|
|
61
|
+
df = pd.read_csv("your_data.csv")
|
|
62
|
+
|
|
63
|
+
# Create a count plot
|
|
64
|
+
fig, ax = dv.get_count_plot(
|
|
65
|
+
var="diagnosis", # Categorical variable to plot
|
|
66
|
+
df=df, # DataFrame containing the data
|
|
67
|
+
show_nan=True, # Show NaN values as a separate category
|
|
68
|
+
save_fig=True # Save the figure to disk
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
# Create a distribution plot
|
|
72
|
+
fig, ax = dv.get_dist_plot(
|
|
73
|
+
var="age", # Numerical variable to plot
|
|
74
|
+
df=df, # DataFrame containing the data
|
|
75
|
+
save_fig=True # Save the figure to disk
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
# Generate statistics tables
|
|
79
|
+
stats_df = dv.get_count_stats_df(
|
|
80
|
+
var="diagnosis", # Categorical variable to analyze
|
|
81
|
+
df=df, # DataFrame containing the data
|
|
82
|
+
save_table=True # Save the table to disk as LaTeX
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# Create stratified visualizations
|
|
86
|
+
fg = dv.get_dist_stratified_plot(
|
|
87
|
+
var="age", # Numerical variable to plot
|
|
88
|
+
df=df, # DataFrame containing the data
|
|
89
|
+
col="gender", # Categorical variable to stratify by
|
|
90
|
+
save_fig=True # Save the figure to disk
|
|
91
|
+
)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Example
|
|
95
|
+
|
|
96
|
+
Here's a complete example of how to use the DataVisualiser class:
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
import pandas as pd
|
|
100
|
+
import numpy as np
|
|
101
|
+
from data_visualiser_package import DataVisualiser
|
|
102
|
+
|
|
103
|
+
# Create a sample dataset
|
|
104
|
+
np.random.seed(42)
|
|
105
|
+
n = 1000
|
|
106
|
+
|
|
107
|
+
# Generate sample data
|
|
108
|
+
data = {
|
|
109
|
+
'age': np.random.normal(50, 15, n),
|
|
110
|
+
'gender': np.random.choice(['Male', 'Female'], n),
|
|
111
|
+
'diagnosis': np.random.choice(['Healthy', 'Condition A', 'Condition B', None], n, p=[0.6, 0.2, 0.15, 0.05]),
|
|
112
|
+
'heart_rate': np.random.normal(80, 10, n),
|
|
113
|
+
'blood_pressure': np.random.normal(120, 15, n)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
# Create a DataFrame
|
|
117
|
+
df = pd.DataFrame(data)
|
|
118
|
+
|
|
119
|
+
# Initialize the DataVisualiser
|
|
120
|
+
dv = DataVisualiser(
|
|
121
|
+
record_unit_name="patient",
|
|
122
|
+
figures_dirpath="./output/figures",
|
|
123
|
+
tables_dirpath="./output/tables",
|
|
124
|
+
create_dirs=True
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
# Create plots
|
|
128
|
+
dv.get_count_plot('gender', df, save_fig=True)
|
|
129
|
+
dv.get_count_plot('diagnosis', df, save_fig=True)
|
|
130
|
+
|
|
131
|
+
# Create stratified count plots
|
|
132
|
+
dv.get_count_stratified_plot('diagnosis', df, col='gender', save_fig=True)
|
|
133
|
+
|
|
134
|
+
# Distribution plots
|
|
135
|
+
dv.get_dist_plot('age', df, save_fig=True)
|
|
136
|
+
dv.get_dist_stratified_plot('age', df, col='gender', save_fig=True)
|
|
137
|
+
dv.get_dist_hued_plot('age', df, hue='gender', save_fig=True)
|
|
138
|
+
|
|
139
|
+
# Generate statistics tables
|
|
140
|
+
dv.get_count_stats_df('diagnosis', df, save_table=True)
|
|
141
|
+
dv.get_dist_stats_df('age', df, save_table=True)
|
|
142
|
+
dv.get_dist_stratified_stats_df('age', df, col='gender', save_table=True)
|
|
143
|
+
|
|
144
|
+
print("All visualizations and tables have been generated successfully!")
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## API Reference
|
|
148
|
+
|
|
149
|
+
### DataVisualiser Class
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
class DataVisualiser(
|
|
153
|
+
record_unit_name="patient",
|
|
154
|
+
figures_dirpath=None,
|
|
155
|
+
tables_dirpath=None,
|
|
156
|
+
create_dirs=False
|
|
157
|
+
)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
#### Count Visualizations
|
|
161
|
+
|
|
162
|
+
- `get_count_plot(var, df, show_nan=True, save_fig=False, plot_kwargs={}, xlabels_rotation=None, forced_order=None)`
|
|
163
|
+
- `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)`
|
|
164
|
+
- `get_count_stats_df(var, df, show_nan=True, save_table=False, percentage=True, add_total=False, round_n_digits=1, forced_order=None)`
|
|
165
|
+
- `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)`
|
|
166
|
+
|
|
167
|
+
#### Distribution Visualizations
|
|
168
|
+
|
|
169
|
+
- `get_dist_plot(var, df, save_fig=False, plot_kwargs={"kde": True}, xlabels_rotation=None)`
|
|
170
|
+
- `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)`
|
|
171
|
+
- `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)`
|
|
172
|
+
- `get_dist_stats_df(var, df, save_table=False)`
|
|
173
|
+
- `get_dist_stratified_stats_df(var, df, col="gender", show_nan_col=True, save_table=False, forced_order_col=None)`
|
|
174
|
+
|
|
175
|
+
## License
|
|
176
|
+
|
|
177
|
+
MIT
|
|
178
|
+
|
|
179
|
+
## Contributing
|
|
180
|
+
|
|
181
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# PyPI Publishing Guide
|
|
2
|
+
|
|
3
|
+
This guide outlines how to build and publish the data-visualiser-package to PyPI.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
Ensure you have the necessary tools:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install build twine
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Building the Package
|
|
14
|
+
|
|
15
|
+
1. Navigate to the root directory of the project:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
cd /path/to/data_visualiser_package
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
2. Build the distribution packages:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
python -m build
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This will create both source and wheel distributions in the `dist/` directory.
|
|
28
|
+
|
|
29
|
+
## Publishing to PyPI
|
|
30
|
+
|
|
31
|
+
### Publishing to Test PyPI (Recommended for testing)
|
|
32
|
+
|
|
33
|
+
1. Upload to Test PyPI:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
python -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
2. Install from Test PyPI to verify:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ data-visualiser-package
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Publishing to PyPI
|
|
46
|
+
|
|
47
|
+
Once you've confirmed everything works on TestPyPI, you can publish to the main PyPI:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
python -m twine upload dist/*
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Versioning
|
|
54
|
+
|
|
55
|
+
When releasing a new version:
|
|
56
|
+
|
|
57
|
+
1. Update the version number in:
|
|
58
|
+
- `pyproject.toml`
|
|
59
|
+
- `setup.py`
|
|
60
|
+
- `src/data_visualiser_package/__init__.py`
|
|
61
|
+
|
|
62
|
+
2. Add release notes to the README.md or CHANGELOG.md file.
|
|
63
|
+
|
|
64
|
+
## Cleaning Up
|
|
65
|
+
|
|
66
|
+
Remove build directories before rebuilding:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
rm -rf build/ dist/ *.egg-info/
|
|
70
|
+
```
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# Data Visualiser Package
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install data-visualiser-package
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- Create count plots and distribution plots
|
|
14
|
+
- Generate stratified visualizations by categorical variables
|
|
15
|
+
- Compute and display statistical tables for numerical and categorical variables
|
|
16
|
+
- Save plots and tables to disk (including LaTeX export)
|
|
17
|
+
- Handling of missing values
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
import pandas as pd
|
|
23
|
+
from data_visualiser_package import DataVisualiser
|
|
24
|
+
|
|
25
|
+
# Create a DataVisualiser instance
|
|
26
|
+
dv = DataVisualiser(
|
|
27
|
+
record_unit_name="patient", # What a single record represents
|
|
28
|
+
figures_dirpath="./figures", # Where to save figures
|
|
29
|
+
tables_dirpath="./tables", # Where to save tables
|
|
30
|
+
create_dirs=True # Create directories if they don't exist
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
# Load your data
|
|
34
|
+
df = pd.read_csv("your_data.csv")
|
|
35
|
+
|
|
36
|
+
# Create a count plot
|
|
37
|
+
fig, ax = dv.get_count_plot(
|
|
38
|
+
var="diagnosis", # Categorical variable to plot
|
|
39
|
+
df=df, # DataFrame containing the data
|
|
40
|
+
show_nan=True, # Show NaN values as a separate category
|
|
41
|
+
save_fig=True # Save the figure to disk
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
# Create a distribution plot
|
|
45
|
+
fig, ax = dv.get_dist_plot(
|
|
46
|
+
var="age", # Numerical variable to plot
|
|
47
|
+
df=df, # DataFrame containing the data
|
|
48
|
+
save_fig=True # Save the figure to disk
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
# Generate statistics tables
|
|
52
|
+
stats_df = dv.get_count_stats_df(
|
|
53
|
+
var="diagnosis", # Categorical variable to analyze
|
|
54
|
+
df=df, # DataFrame containing the data
|
|
55
|
+
save_table=True # Save the table to disk as LaTeX
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
# Create stratified visualizations
|
|
59
|
+
fg = dv.get_dist_stratified_plot(
|
|
60
|
+
var="age", # Numerical variable to plot
|
|
61
|
+
df=df, # DataFrame containing the data
|
|
62
|
+
col="gender", # Categorical variable to stratify by
|
|
63
|
+
save_fig=True # Save the figure to disk
|
|
64
|
+
)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Example
|
|
68
|
+
|
|
69
|
+
Here's a complete example of how to use the DataVisualiser class:
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
import pandas as pd
|
|
73
|
+
import numpy as np
|
|
74
|
+
from data_visualiser_package import DataVisualiser
|
|
75
|
+
|
|
76
|
+
# Create a sample dataset
|
|
77
|
+
np.random.seed(42)
|
|
78
|
+
n = 1000
|
|
79
|
+
|
|
80
|
+
# Generate sample data
|
|
81
|
+
data = {
|
|
82
|
+
'age': np.random.normal(50, 15, n),
|
|
83
|
+
'gender': np.random.choice(['Male', 'Female'], n),
|
|
84
|
+
'diagnosis': np.random.choice(['Healthy', 'Condition A', 'Condition B', None], n, p=[0.6, 0.2, 0.15, 0.05]),
|
|
85
|
+
'heart_rate': np.random.normal(80, 10, n),
|
|
86
|
+
'blood_pressure': np.random.normal(120, 15, n)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
# Create a DataFrame
|
|
90
|
+
df = pd.DataFrame(data)
|
|
91
|
+
|
|
92
|
+
# Initialize the DataVisualiser
|
|
93
|
+
dv = DataVisualiser(
|
|
94
|
+
record_unit_name="patient",
|
|
95
|
+
figures_dirpath="./output/figures",
|
|
96
|
+
tables_dirpath="./output/tables",
|
|
97
|
+
create_dirs=True
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
# Create plots
|
|
101
|
+
dv.get_count_plot('gender', df, save_fig=True)
|
|
102
|
+
dv.get_count_plot('diagnosis', df, save_fig=True)
|
|
103
|
+
|
|
104
|
+
# Create stratified count plots
|
|
105
|
+
dv.get_count_stratified_plot('diagnosis', df, col='gender', save_fig=True)
|
|
106
|
+
|
|
107
|
+
# Distribution plots
|
|
108
|
+
dv.get_dist_plot('age', df, save_fig=True)
|
|
109
|
+
dv.get_dist_stratified_plot('age', df, col='gender', save_fig=True)
|
|
110
|
+
dv.get_dist_hued_plot('age', df, hue='gender', save_fig=True)
|
|
111
|
+
|
|
112
|
+
# Generate statistics tables
|
|
113
|
+
dv.get_count_stats_df('diagnosis', df, save_table=True)
|
|
114
|
+
dv.get_dist_stats_df('age', df, save_table=True)
|
|
115
|
+
dv.get_dist_stratified_stats_df('age', df, col='gender', save_table=True)
|
|
116
|
+
|
|
117
|
+
print("All visualizations and tables have been generated successfully!")
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## API Reference
|
|
121
|
+
|
|
122
|
+
### DataVisualiser Class
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
class DataVisualiser(
|
|
126
|
+
record_unit_name="patient",
|
|
127
|
+
figures_dirpath=None,
|
|
128
|
+
tables_dirpath=None,
|
|
129
|
+
create_dirs=False
|
|
130
|
+
)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### Count Visualizations
|
|
134
|
+
|
|
135
|
+
- `get_count_plot(var, df, show_nan=True, save_fig=False, plot_kwargs={}, xlabels_rotation=None, forced_order=None)`
|
|
136
|
+
- `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)`
|
|
137
|
+
- `get_count_stats_df(var, df, show_nan=True, save_table=False, percentage=True, add_total=False, round_n_digits=1, forced_order=None)`
|
|
138
|
+
- `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)`
|
|
139
|
+
|
|
140
|
+
#### Distribution Visualizations
|
|
141
|
+
|
|
142
|
+
- `get_dist_plot(var, df, save_fig=False, plot_kwargs={"kde": True}, xlabels_rotation=None)`
|
|
143
|
+
- `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)`
|
|
144
|
+
- `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)`
|
|
145
|
+
- `get_dist_stats_df(var, df, save_table=False)`
|
|
146
|
+
- `get_dist_stratified_stats_df(var, df, col="gender", show_nan_col=True, save_table=False, forced_order_col=None)`
|
|
147
|
+
|
|
148
|
+
## License
|
|
149
|
+
|
|
150
|
+
MIT
|
|
151
|
+
|
|
152
|
+
## Contributing
|
|
153
|
+
|
|
154
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""
|
|
2
|
+
DataVisualiser Package Demo
|
|
3
|
+
|
|
4
|
+
This script demonstrates how to use the DataVisualiser package with a sample dataset.
|
|
5
|
+
"""
|
|
6
|
+
import os
|
|
7
|
+
import pandas as pd
|
|
8
|
+
import numpy as np
|
|
9
|
+
from data_visualiser_package import DataVisualiser
|
|
10
|
+
|
|
11
|
+
def main():
|
|
12
|
+
# Create output directories
|
|
13
|
+
os.makedirs("./demo_output/figures", exist_ok=True)
|
|
14
|
+
os.makedirs("./demo_output/tables", exist_ok=True)
|
|
15
|
+
|
|
16
|
+
# Create a sample dataset
|
|
17
|
+
np.random.seed(42)
|
|
18
|
+
n = 1000
|
|
19
|
+
|
|
20
|
+
# Generate sample data
|
|
21
|
+
data = {
|
|
22
|
+
'age': np.random.normal(50, 15, n),
|
|
23
|
+
'gender': np.random.choice(['Male', 'Female'], n),
|
|
24
|
+
'diagnosis': np.random.choice(['Healthy', 'Condition A', 'Condition B', None], n, p=[0.6, 0.2, 0.15, 0.05]),
|
|
25
|
+
'heart_rate': np.random.normal(80, 10, n),
|
|
26
|
+
'blood_pressure': np.random.normal(120, 15, n),
|
|
27
|
+
'treatment': np.random.choice(['Drug A', 'Drug B', 'Placebo', None], n),
|
|
28
|
+
'response': np.random.choice(['Good', 'Moderate', 'Poor', None], n, p=[0.5, 0.3, 0.15, 0.05]),
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
# Create a DataFrame
|
|
32
|
+
df = pd.DataFrame(data)
|
|
33
|
+
|
|
34
|
+
print("Sample data created:")
|
|
35
|
+
print(df.head())
|
|
36
|
+
print(f"\nDataset shape: {df.shape}")
|
|
37
|
+
print("\nData types:")
|
|
38
|
+
print(df.dtypes)
|
|
39
|
+
print("\nMissing values:")
|
|
40
|
+
print(df.isna().sum())
|
|
41
|
+
|
|
42
|
+
# Initialize the DataVisualiser
|
|
43
|
+
dv = DataVisualiser(
|
|
44
|
+
record_unit_name="patient",
|
|
45
|
+
figures_dirpath="./demo_output/figures",
|
|
46
|
+
tables_dirpath="./demo_output/tables",
|
|
47
|
+
create_dirs=True
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
print("\n1. Creating count plots...")
|
|
51
|
+
# Create count plots for categorical variables
|
|
52
|
+
dv.get_count_plot('gender', df, save_fig=True)
|
|
53
|
+
dv.get_count_plot('diagnosis', df, save_fig=True)
|
|
54
|
+
dv.get_count_plot('treatment', df, save_fig=True)
|
|
55
|
+
dv.get_count_plot('response', df, save_fig=True)
|
|
56
|
+
|
|
57
|
+
print("2. Creating stratified count plots...")
|
|
58
|
+
# Create stratified count plots
|
|
59
|
+
dv.get_count_stratified_plot('diagnosis', df, col='gender', save_fig=True)
|
|
60
|
+
dv.get_count_stratified_plot('response', df, col='treatment', save_fig=True)
|
|
61
|
+
|
|
62
|
+
print("3. Creating distribution plots...")
|
|
63
|
+
# Distribution plots for numerical variables
|
|
64
|
+
dv.get_dist_plot('age', df, save_fig=True)
|
|
65
|
+
dv.get_dist_plot('heart_rate', df, save_fig=True)
|
|
66
|
+
dv.get_dist_plot('blood_pressure', df, save_fig=True)
|
|
67
|
+
|
|
68
|
+
print("4. Creating stratified distribution plots...")
|
|
69
|
+
# Create stratified distribution plots
|
|
70
|
+
dv.get_dist_stratified_plot('age', df, col='gender', save_fig=True)
|
|
71
|
+
dv.get_dist_stratified_plot('heart_rate', df, col='diagnosis', save_fig=True)
|
|
72
|
+
|
|
73
|
+
print("5. Creating hued distribution plots...")
|
|
74
|
+
# Create hued distribution plots
|
|
75
|
+
dv.get_dist_hued_plot('blood_pressure', df, hue='gender', save_fig=True)
|
|
76
|
+
|
|
77
|
+
print("6. Generating statistics tables...")
|
|
78
|
+
# Generate statistics tables
|
|
79
|
+
count_stats = dv.get_count_stats_df('diagnosis', df, save_table=True)
|
|
80
|
+
print("\nCount statistics for diagnosis:")
|
|
81
|
+
print(count_stats)
|
|
82
|
+
|
|
83
|
+
dist_stats = dv.get_dist_stats_df('age', df, save_table=True)
|
|
84
|
+
print("\nDistribution statistics for age:")
|
|
85
|
+
print(dist_stats)
|
|
86
|
+
|
|
87
|
+
strat_dist_stats = dv.get_dist_stratified_stats_df('heart_rate', df, col='gender', save_table=True)
|
|
88
|
+
print("\nStratified distribution statistics for heart_rate by gender:")
|
|
89
|
+
print(strat_dist_stats)
|
|
90
|
+
|
|
91
|
+
print("\nAll visualizations and tables have been generated successfully!")
|
|
92
|
+
print(f"Check the demo_output directory for the generated files.")
|
|
93
|
+
|
|
94
|
+
if __name__ == "__main__":
|
|
95
|
+
main()
|