Class: QgsStringStatisticalSummary

class qgis.core.QgsStringStatisticalSummary

Bases: sip.wrapper

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 via setStatistics().

QgsStringStatisticalSummary(stats: Union[Qgis.StringStatistics, Qgis.StringStatistic] = Qgis.StringStatistic.All) Constructor for QgsStringStatistics

Parameters:

stats – flags for statistics to calculate

QgsStringStatisticalSummary(QgsStringStatisticalSummary)

Enums

Statistic

alias of StringStatistic

Methods

addString

Adds a single string to the statistics calculation.

addValue

Adds a single variant to the statistics calculation.

calculate

Calculates summary statistics for an entire list of strings at once.

calculateFromVariants

Calculates summary statistics for an entire list of variants at once.

count

Returns the calculated count of values.

countDistinct

Returns the number of distinct string values.

countMissing

Returns the number of missing (null) string values.

displayName

Returns the friendly display name for a statistic

distinctValues

Returns the set of distinct string values.

finalize

Must be called after adding all strings with addString() and before retrieving any calculated string statistics.

majority

Returns the most common string.

max

Returns the maximum (non-null) string value.

maxLength

Returns the maximum length of strings.

meanLength

Returns the mean length of strings.

min

Returns the minimum (non-null) string value.

minLength

Returns the minimum length of strings.

minority

Returns the least common string.

reset

Resets the calculated values

setStatistics

Sets flags which specify which statistics will be calculated.

statistic

Returns the value of a specified statistic

statistics

Returns flags which specify which statistics will be calculated.

Statistic

alias of StringStatistic

Statistics

alias of StringStatistics

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 calculations

Note

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

See also

calculate()

See also

addValue()

See also

finalize()

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 calculations

Note

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

See also

finalize()

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

addString()

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

calculate()

See also

addValue()

count(self) int

Returns the calculated count of values.

Return type:

int

countDistinct(self) int

Returns the number of distinct string values.

See also

distinctValues()

Return type:

int

countMissing(self) int

Returns the number of missing (null) string values.

Return type:

int

displayName(statistic: Qgis.StringStatistic) str

Returns the friendly display name for a statistic

Parameters:

statistic (Qgis.StringStatistic) – statistic to return name for

Return type:

str

distinctValues(self) Set[str]

Returns the set of distinct string values.

See also

countDistinct()

Return type:

Set[str]

finalize(self)

Must be called after adding all strings with addString() and before retrieving any calculated string statistics.

See also

addString()

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

minority()

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.

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

majority()

New in version 3.14.

Return type:

str

reset(self)

Resets the calculated values

setStatistics(self, stats: Qgis.StringStatistics | Qgis.StringStatistic)

Sets flags which specify which statistics will be calculated. Some statistics are always calculated (e.g., count).

Parameters:

stats (Union[Qgis.StringStatistics) – flags for statistics to calculate

See also

statistics()

statistic(self, stat: Qgis.StringStatistic) Any

Returns the value of a specified statistic

Parameters:

stat (Qgis.StringStatistic) – statistic to return

Return type:

Any

Returns:

calculated value of statistic

statistics(self) Qgis.StringStatistics

Returns flags which specify which statistics will be calculated. Some statistics are always calculated (e.g., count).

See also

setStatistics()

Return type:

Qgis.StringStatistics