Class: QgsStringStatisticalSummary¶
-
class
qgis.core.
QgsStringStatisticalSummary
(stats: Union[QgsStringStatisticalSummary.Statistics, QgsStringStatisticalSummary.Statistic] = QgsStringStatisticalSummary.All)¶ Bases:
sip.wrapper
Constructor for
QgsStringStatistics
- Parameters
stats (Union[QgsStringStatisticalSummary.Statistics) – flags for statistics to calculate
QgsStringStatisticalSummary(
QgsStringStatisticalSummary
)Calculator for summary statistics and aggregates for a list of strings.
Statistics are calculated by calling
calculate()
and passing a list of strings. 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 string to the statistics calculation.
Adds a single variant to the statistics calculation.
Calculates summary statistics for an entire list of strings at once.
Calculates summary statistics for an entire list of variants at once.
Returns the calculated count of values.
Returns the number of distinct string values.
Returns the number of missing (null) string values.
Returns the friendly display name for a statistic
Returns the set of distinct string values.
Must be called after adding all strings with
addString()
and before retrieving any calculated string statistics.Returns the most common string.
Returns the maximum (non-null) string value.
Returns the maximum length of strings.
Returns the mean length of strings.
Returns the minimum (non-null) string value.
Returns the minimum length of strings.
Returns the least common string.
Resets the calculated values
Sets flags which specify which statistics will be calculated.
Returns the value of a specified statistic
Returns flags which specify which statistics will be calculated.
Attributes
-
All
= 1023¶
-
Count
= 1¶
-
CountDistinct
= 2¶
-
CountMissing
= 4¶
-
Majority
= 512¶
-
Max
= 16¶
-
MaximumLength
= 64¶
-
MeanLength
= 128¶
-
Min
= 8¶
-
MinimumLength
= 32¶
-
Minority
= 256¶
-
class
Statistic
¶ Bases:
int
-
class
Statistics
¶ Bases:
sip.wrapper
QgsStringStatisticalSummary.Statistics(Union[QgsStringStatisticalSummary.Statistics, QgsStringStatisticalSummary.Statistic]) QgsStringStatisticalSummary.Statistics(QgsStringStatisticalSummary.Statistics)
-
addString
(self, string: str)¶ Adds a single string to the statistics calculation. Calling this method allows strings to be added to the calculation one at a time. For large quantities of strings this may be more efficient then first adding all the strings to a list and calling
calculate()
.- Parameters
string (str) – string to add
Note
call
reset()
before adding the first string using this method to clear the results from any previous calculationsNote
finalize()
must be called after adding the final string and before retrieving calculated statistics.See also
See also
See also
-
addValue
(self, value: Any)¶ Adds a single variant to the statistics calculation. Calling this method allows variants to be added to the calculation one at a time. For large quantities of variants this may be more efficient then first adding all the variants to a list and calling
calculateFromVariants()
.- Parameters
value (Any) – variant to add
Note
call
reset()
before adding the first string 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
-
calculate
(self, values: Iterable[str])¶ Calculates summary statistics for an entire list of strings at once.
- Parameters
values (Iterable[str]) – list of strings
See also
See also
-
calculateFromVariants
(self, values: Iterable[Any])¶ Calculates summary statistics for an entire list of variants at once. Any non-string variants will be ignored.
- Parameters
values (Iterable[Any]) – list of variants
See also
See also
-
count
(self) → int¶ Returns the calculated count of values.
- Return type
int
-
countDistinct
(self) → int¶ Returns the number of distinct string values.
See also
- Return type
int
-
countMissing
(self) → int¶ Returns the number of missing (null) string values.
- Return type
int
-
displayName
(statistic: QgsStringStatisticalSummary.Statistic) → str¶ Returns the friendly display name for a statistic
- Parameters
statistic (QgsStringStatisticalSummary.Statistic) – statistic to return name for
- Return type
str
-
distinctValues
(self) → Set[str]¶ Returns the set of distinct string values.
See also
- Return type
Set[str]
-
finalize
(self)¶ Must be called after adding all strings with
addString()
and before retrieving any calculated string statistics.See also
-
majority
(self) → str¶ Returns the most common string. 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.
See also
New in version 3.14.
- Return type
str
-
max
(self) → str¶ Returns the maximum (non-null) string value.
- Return type
str
-
maxLength
(self) → int¶ Returns the maximum length of strings.
- Return type
int
-
meanLength
(self) → float¶ Returns the mean length of strings.
New in version 3.0.
- Return type
float
-
min
(self) → str¶ Returns the minimum (non-null) string value.
- Return type
str
-
minLength
(self) → int¶ Returns the minimum length of strings.
- Return type
int
-
minority
(self) → str¶ Returns the least common string. 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.
See also
New in version 3.14.
- Return type
str
-
reset
(self)¶ Resets the calculated values
-
setStatistics
(self, stats: Union[QgsStringStatisticalSummary.Statistics, QgsStringStatisticalSummary.Statistic])¶ Sets flags which specify which statistics will be calculated. Some statistics are always calculated (e.g., count).
- Parameters
stats (Union[QgsStringStatisticalSummary.Statistics) – flags for statistics to calculate
See also
-
statistic
(self, stat: QgsStringStatisticalSummary.Statistic) → Any¶ Returns the value of a specified statistic
- Parameters
stat (QgsStringStatisticalSummary.Statistic) – statistic to return
- Return type
Any
- Returns
calculated value of statistic
-
statistics
(self) → QgsStringStatisticalSummary.Statistics¶ Returns flags which specify which statistics will be calculated. Some statistics are always calculated (e.g., count).
See also
- Return type