datasette-statistics
SQL statistics functions for Datasette
Installation
Install this plugin in the same environment as Datasette.
datasette install datasette-statistics
Usage
This plugin adds new SQL aggregate functions for use within Datasette:
-
statistics_mean()
for calculating the mean -
statistics_geometric_mean()
for calculating the geometric mean (requires Python 3.8+) -
statistics_median()
for calculating the median -
statistics_median_low()
for calculating the low median -
statistics_median_high()
for calculating the high median -
statistics_mode()
for calculating the mode -
statistics_stdev()
for calculating the sample standard deviation -
statistics_pstdev()
for calculating the population standard deviation -
statistics_variance()
for calculating the sample variance -
statistics_pvariance()
for calculating the population variance
These all use the implementations from the Python statistics library.
Use them like this:
select statistics_mean(numeric_column) from mytable
Development
To set up this plugin locally, first checkout the code. Then create a new virtual environment:
cd datasette-statistics
python3 -mvenv venv
source venv/bin/activate
Or if you are using pipenv
:
pipenv shell
Now install the dependencies and test dependencies:
pip install -e '.[test]'
To run the tests:
pytest