Class: QgsStatisticalSummary¶
-
class
qgis.core.
QgsStatisticalSummary
(stats: Union[QgsStatisticalSummary.Statistics, QgsStatisticalSummary.Statistic] = QgsStatisticalSummary.All)¶ Bases:
sip.wrapper
Constructor for QgsStatisticalSummary
- Parameters
stats (Union[QgsStatisticalSummary.Statistics) – 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 viasetStatistics()
.Methods
Adds a single value to the statistics calculation.
Adds a single value to the statistics calculation.
Calculates summary statistics for a list of values
Returns calculated count of values
Returns the number of missing (null) values
Returns the friendly display name for a
statistic
.Must be called after adding all values with
addValues()
and before retrieving any calculated statistics.Returns the first value obtained.
Returns the first quartile of the values.
Returns the inter quartile range of the values.
Returns the last value obtained.
Returns majority of values.
Returns calculated maximum from values.
Returns calculated mean of values.
Returns calculated median of values.
Returns calculated minimum from values.
Returns minority of values.
Returns calculated range (difference between maximum and minimum values).
Resets the calculated values
Returns sample standard deviation.
Sets flags which specify which statistics will be calculated.
Returns a short, friendly display name for a
statistic
, suitable for use in a field name.Returns population standard deviation.
Returns the value of a specified statistic
Returns flags which specify which statistics will be calculated.
Returns calculated sum of values
Returns the third quartile of the values.
Returns variety of values.
Attributes
-
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
¶ 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 (float) – value to add
Note
call
reset()
before adding the first value using this method to clear the results from any previous calculationsNote
finalize()
must be called after adding the final value and before retrieving calculated statistics.See also
See also
See also
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 calculationsNote
finalize()
must be called after adding the final value and before retrieving calculated statistics.See also
See also
See also
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
- 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
See also
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
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
See also
- 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
See also
- Return type
float
-
last
(self) → float¶ Returns the last value obtained. A NaN value may be returned if no values were encountered.
See also
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
- 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
- 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
- Return type
float
-
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 (Union[QgsStatisticalSummary.Statistics) – flags for statistics to calculate
See also
-
shortName
(statistic: QgsStatisticalSummary.Statistic) → str¶ Returns a short, friendly display name for a
statistic
, suitable for use in a field name.See also
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
- 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
- Return type
-
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
See also
- 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