agate-stats 0.4.2#

Build status Coverage status PyPI downloads Version License Support Python versions

agate-stats adds statistical methods to agate.

Important links:

Install#

To install:

pip install agate-stats

For details on development or supported platforms see the agate documentation.

Usage#

agate-stats uses a monkey patching pattern to add additional statistical methods to all agate.Table instances.

import agate
import agatestats

Importing agate-stats adds methods to agate.Table. For example, to filter a table to only those rows whose cost value is an outliers by more than 3 standard deviations you would use TableStats.stdev_outliers():

outliers = table.stdev_outliers('price')

In addition to Table methods agatestats also includes a variety of additional aggregations and computations. See the API section of the docs for a complete list of all the added features.

API#

agatestats.table.stdev_outliers(self, column_name, deviations=3, reject=False)#

A wrapper around Table.where that filters the dataset to rows where the value of the column are more than some number of standard deviations from the mean.

This method makes no attempt to validate that the distribution of your data is normal.

There are well-known cases in which this algorithm will fail to identify outliers. For a more robust measure see TableStats.mad_outliers().

Parameters:
  • column_name – The name of the column to compute outliers on.

  • deviations – The number of deviations from the mean a data point must be to qualify as an outlier.

  • reject – If True then the new Table will contain everything except the outliers.

Returns:

A new Table.

agatestats.table.mad_outliers(self, column_name, deviations=3, reject=False)#

A wrapper around Table.where that filters the dataset to rows where the value of the column are more than some number of median absolute deviations from the median.

This method makes no attempt to validate that the distribution of your data is normal.

Parameters:
  • column_name – The name of the column to compute outliers on.

  • deviations – The number of deviations from the median a data point must be to qualify as an outlier.

  • reject – If True then the new Table will contain everything except the outliers.

Returns:

A new Table.

agatestats.tableset.stdev_outliers(self, column_name, deviations=3, reject=False)#

A wrapper around Table.where that filters the dataset to rows where the value of the column are more than some number of standard deviations from the mean.

This method makes no attempt to validate that the distribution of your data is normal.

There are well-known cases in which this algorithm will fail to identify outliers. For a more robust measure see TableStats.mad_outliers().

Parameters:
  • column_name – The name of the column to compute outliers on.

  • deviations – The number of deviations from the mean a data point must be to qualify as an outlier.

  • reject – If True then the new Table will contain everything except the outliers.

Returns:

A new Table.

agatestats.tableset.mad_outliers(self, column_name, deviations=3, reject=False)#

A wrapper around Table.where that filters the dataset to rows where the value of the column are more than some number of median absolute deviations from the median.

This method makes no attempt to validate that the distribution of your data is normal.

Parameters:
  • column_name – The name of the column to compute outliers on.

  • deviations – The number of deviations from the median a data point must be to qualify as an outlier.

  • reject – If True then the new Table will contain everything except the outliers.

Returns:

A new Table.

class agatestats.aggregations.PearsonCorrelation(x_column_name, y_column_name)#

Bases: Aggregation

Calculates the Pearson correlation coefficient for x_column_name and y_column_name.

Returns a number between -1 and 1 with 0 implying no correlation. A correlation close to 1 implies a high positive correlation i.e. as x increases so does y. A correlation close to -1 implies a high negative correlation i.e. as x increases, y decreases.

Note: this implementation is borrowed from the MIT licensed latimes-calculate. Thanks, LAT!

Parameters:
  • x_column_name – The name of a column.

  • y_column_name – The name of a column.

get_aggregate_data_type(table)#

Get the data type that should be used when using this aggregation with a TableSet to produce a new column.

Should raise UnsupportedAggregationError if this column does not support aggregation into a TableSet. (For example, if it does not return a single value.)

run(table)#
Returns:

decimal.Decimal.

class agatestats.computations.ZScores(column_name)#

Bases: Computation

Computes the z-scores (standard scores) of a given column.

get_computed_data_type(table)#

Returns an instantiated DataType which will be appended to the table.

validate(table)#

Perform any checks necessary to verify this computation can run on the provided table without errors. This is called by Table.compute() before run().

run(table)#

When invoked with a table, returns a sequence of new column values.

Authors#

The following individuals have contributed code to agate-stats:

Changelog#

0.4.2 - February 23, 2024#

  • Add Python 3.8, 3.9, 3.10, 3.11, 3.12 support.

  • Drop support for Python 2.7 (EOL 2020-01-01), 3.4 (2019-03-18), 3.5 (2020-09-13), 3.6 (2021-12-23), 3.7 (2023-06-27).

0.4.1 - October 3, 2023#

0.4.0 - December 19, 2016#

  • Update ZScores to use new Computation interface.

  • Remove monkey patching.

  • Upgrade agate dependency to 1.5.0.

0.3.1 - November 5, 2015#

  • Fix packaging issue.

0.3.0 - November 5, 2015#

  • Added usage documentation.

  • Convert PearsonCorrelation to an aggregation.

  • Update required version of agate to 1.1.0.

  • Removed Python 2.6 support.

0.2.0 - October 22, 2015#

  • Update to support agate 1.0.0.

0.1.0 - October 6, 2015#

  • Initial version.

License#

The MIT License

Copyright (c) 2015 Christopher Groskopf and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Indices and tables#