Class: QgsStatisticalSummary

class qgis.core.QgsStatisticalSummary(stats: Union[QgsStatisticalSummary.Statistics, QgsStatisticalSummary.Statistic] = QgsStatisticalSummary.All)

Bases: sip.wrapper

Constructor for QgsStatisticalSummary

Parameters

stats – flags for statistics to calculate

QgsStatisticalSummary(QgsStatisticalSummary)

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: Enums

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.

firstQuartile

Returns the first quartile of the values.

interQuartileRange

Returns the inter quartile range of the values.

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.

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.

Signals

Attributes

All

Count

CountMissing

FirstQuartile

InterQuartileRange

Majority

Max

Mean

Median

Min

Minority

Range

StDev

StDevSample

Sum

ThirdQuartile

Variety

All = 65503
Count = 1
CountMissing = 32770
FirstQuartile = 4096
InterQuartileRange = 16384
Majority = 1024
Max = 128
Mean = 4
Median = 8
Min = 64
Minority = 512
Range = 256
StDev = 16
StDevSample = 32
class Statistic

Bases: int

class Statistics

Bases: sip.wrapper

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

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 – 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 – 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 – list of doubles

count(self) → int

Returns calculated count of values

countMissing(self) → int

Returns the number of missing (null) values

New in version 2.16.

displayName(statistic: QgsStatisticalSummary.Statistic) → str

Returns the friendly display name for a statistic

Parameters

statistic – statistic to return name for

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.

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()

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()

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. A NaN value may be returned if the majority cannot be calculated.

See also

minority()

max(self) → float

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

mean(self) → float

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

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.

min(self) → float

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

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. A NaN value may be returned if the minority cannot be calculated.

See also

majority()

range(self) → float

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

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()

setStatistics(self, stats: Union[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 – flags for statistics to calculate

See also

statistics()

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()

statistic(self, stat: QgsStatisticalSummary.Statistic) → float

Returns the value of a specified statistic

Parameters

stat – statistic to return

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()

sum(self) → float

Returns calculated sum of values

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()

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.