Class: QgsStatisticalSummary

class qgis.core.QgsStatisticalSummary

Bases: sip.wrapper

Calculator for summary statistics for a list of doubles.

Statistics are calculated by calling calculate() and passing a list of doubles. The individual statistics can then be retrieved using the associated methods. Note that not all statistics are calculated by default. Statistics which require slower computations are only calculated by specifying the statistic in the constructor or via setStatistics().

New in version 2.9.

QgsStatisticalSummary(stats: Union[QgsStatisticalSummary.Statistics, QgsStatisticalSummary.Statistic] = QgsStatisticalSummary.All) Constructor for QgsStatisticalSummary

Parameters:

stats – flags for statistics to calculate

QgsStatisticalSummary(QgsStatisticalSummary)

Methods

addValue

Adds a single value to the statistics calculation.

addVariant

Adds a single value to the statistics calculation.

calculate

Calculates summary statistics for a list of values

count

Returns calculated count of values

countMissing

Returns the number of missing (null) values

displayName

Returns the friendly display name for a statistic.

finalize

Must be called after adding all values with addValues() and before retrieving any calculated statistics.

first

Returns the first value obtained.

firstQuartile

Returns the first quartile of the values.

interQuartileRange

Returns the inter quartile range of the values.

last

Returns the last value obtained.

majority

Returns majority of values.

max

Returns calculated maximum from values.

mean

Returns calculated mean of values.

median

Returns calculated median of values.

min

Returns calculated minimum from values.

minority

Returns minority of values.

range

Returns calculated range (difference between maximum and minimum values).

reset

Resets the calculated values

sampleStDev

Returns sample standard deviation.

setStatistics

Sets flags which specify which statistics will be calculated.

shortName

Returns a short, friendly display name for a statistic, suitable for use in a field name.

stDev

Returns population standard deviation.

statistic

Returns the value of a specified statistic

statistics

Returns flags which specify which statistics will be calculated.

sum

Returns calculated sum of values

thirdQuartile

Returns the third quartile of the values.

variety

Returns variety of values.

Attributes

All

Count

CountMissing

First

FirstQuartile

InterQuartileRange

Last

Majority

Max

Mean

Median

Min

Minority

Range

StDev

StDevSample

Sum

ThirdQuartile

Variety

All = 262111
Count = 1
CountMissing = 32768
First = 65536
FirstQuartile = 4096
InterQuartileRange = 16384
Last = 131072
Majority = 1024
Max = 128
Mean = 4
Median = 8
Min = 64
Minority = 512
Range = 256
StDev = 16
StDevSample = 32
class Statistic

Bases: int

class Statistics
class Statistics(Union[QgsStatisticalSummary.Statistics, QgsStatisticalSummary.Statistic])
class Statistics(QgsStatisticalSummary.Statistics)

Bases: sip.wrapper

Sum = 2
ThirdQuartile = 8192
Variety = 2048
addValue(self, value: float)

Adds a single value to the statistics calculation. Calling this method allows values to be added to the calculation one at a time. For large quantities of values this may be more efficient then first adding all the values to a list and calling calculate().

Parameters:

value (float) – value to add

Note

call reset() before adding the first value using this method to clear the results from any previous calculations

Note

finalize() must be called after adding the final value and before retrieving calculated statistics.

See also

calculate()

See also

addVariant()

See also

finalize()

New in version 2.16.

addVariant(self, value: Any)

Adds a single value to the statistics calculation. Calling this method allows values to be added to the calculation one at a time. For large quantities of values this may be more efficient then first adding all the values to a list and calling calculate().

Parameters:

value (Any) – variant containing to add. Non-numeric values are treated as null.

Note

call reset() before adding the first value using this method to clear the results from any previous calculations

Note

finalize() must be called after adding the final value and before retrieving calculated statistics.

See also

addValue()

See also

calculate()

See also

finalize()

New in version 2.16.

calculate(self, values: Iterable[float])

Calculates summary statistics for a list of values

Parameters:

values (Iterable[float]) – list of doubles

count(self) int

Returns calculated count of values

Return type:

int

countMissing(self) int

Returns the number of missing (null) values

New in version 2.16.

Return type:

int

displayName(statistic: QgsStatisticalSummary.Statistic) str

Returns the friendly display name for a statistic.

See also

shortName()

Parameters:

statistic (QgsStatisticalSummary.Statistic) –

Return type:

str

finalize(self)

Must be called after adding all values with addValues() and before retrieving any calculated statistics.

See also

addValue()

See also

addVariant()

New in version 2.16.

first(self) float

Returns the first value obtained. A NaN value may be returned if no values were encountered.

See also

last()

New in version 3.6.

Return type:

float

firstQuartile(self) float

Returns the first quartile of the values. The quartile is calculated using the “Tukey’s hinges” method. A NaN value may be returned if the first quartile cannot be calculated.

See also

thirdQuartile()

Return type:

float

interQuartileRange(self) float

Returns the inter quartile range of the values. The quartiles are calculated using the “Tukey’s hinges” method. A NaN value may be returned if the IQR cannot be calculated.

See also

firstQuartile()

See also

thirdQuartile()

Return type:

float

last(self) float

Returns the last value obtained. A NaN value may be returned if no values were encountered.

See also

first()

New in version 3.6.

Return type:

float

majority(self) float

Returns majority of values. The majority is the value with most occurrences in the list. This is only calculated if Statistic.Majority has been specified in the constructor or via setStatistics. If multiple values match, return the first value relative to the initial values order. A NaN value may be returned if the minority cannot be calculated.

See also

minority()

Return type:

float

max(self) float

Returns calculated maximum from values. A NaN value may be returned if the maximum cannot be calculated.

Return type:

float

mean(self) float

Returns calculated mean of values. A NaN value may be returned if the mean cannot be calculated.

Return type:

float

median(self) float

Returns calculated median of values. This is only calculated if Statistic.Median has been specified in the constructor or via setStatistics. A NaN value may be returned if the median cannot be calculated.

Return type:

float

min(self) float

Returns calculated minimum from values. A NaN value may be returned if the minimum cannot be calculated.

Return type:

float

minority(self) float

Returns minority of values. The minority is the value with least occurrences in the list. This is only calculated if Statistic.Minority has been specified in the constructor or via setStatistics. If multiple values match, return the first value relative to the initial values order. A NaN value may be returned if the minority cannot be calculated.

See also

majority()

Return type:

float

range(self) float

Returns calculated range (difference between maximum and minimum values). A NaN value may be returned if the range cannot be calculated.

Return type:

float

reset(self)

Resets the calculated values

sampleStDev(self) float

Returns sample standard deviation. This is only calculated if Statistic.StDev has been specified in the constructor or via setStatistics. A NaN value may be returned if the standard deviation cannot be calculated.

See also

stDev()

Return type:

float

setStatistics(self, stats: QgsStatisticalSummary.Statistics | QgsStatisticalSummary.Statistic)

Sets flags which specify which statistics will be calculated. Some statistics are always calculated (e.g., sum, min and max).

Parameters:

stats (Union[QgsStatisticalSummary.Statistics) – flags for statistics to calculate

See also

statistics()

shortName(statistic: QgsStatisticalSummary.Statistic) str

Returns a short, friendly display name for a statistic, suitable for use in a field name.

See also

displayName()

New in version 3.6.

Parameters:

statistic (QgsStatisticalSummary.Statistic) –

Return type:

str

stDev(self) float

Returns population standard deviation. This is only calculated if Statistic.StDev has been specified in the constructor or via setStatistics. A NaN value may be returned if the standard deviation cannot be calculated.

See also

sampleStDev()

Return type:

float

statistic(self, stat: QgsStatisticalSummary.Statistic) float

Returns the value of a specified statistic

Parameters:

stat (QgsStatisticalSummary.Statistic) – statistic to return

Return type:

float

Returns:

calculated value of statistic. A NaN value may be returned for invalid statistics.

statistics(self) QgsStatisticalSummary.Statistics

Returns flags which specify which statistics will be calculated. Some statistics are always calculated (e.g., sum, min and max).

See also

setStatistics()

Return type:

QgsStatisticalSummary.Statistics

sum(self) float

Returns calculated sum of values

Return type:

float

thirdQuartile(self) float

Returns the third quartile of the values. The quartile is calculated using the “Tukey’s hinges” method. A NaN value may be returned if the third quartile cannot be calculated.

See also

firstQuartile()

Return type:

float

variety(self) int

Returns variety of values. The variety is the count of unique values from the list. This is only calculated if Statistic.Variety has been specified in the constructor or via setStatistics.

Return type:

int