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

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.

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.

Static Methods

displayName

Returns the friendly display name for a statistic

class qgis.core.QgsStringStatisticalSummary[source]

Bases: object

__init__(stats: Qgis.StringStatistics | Qgis.StringStatistic = Qgis.StringStatistic.All)

Constructor for QgsStringStatistics

Parameters:

stats (Union[Qgis.StringStatistics, Qgis.StringStatistic] = Qgis.StringStatistic.All) – flags for statistics to calculate

__init__(a0: QgsStringStatisticalSummary)
Parameters:

a0 (QgsStringStatisticalSummary)

Statistic

alias of StringStatistic

Statistics

alias of StringStatistics

addString(self, string: str | None)[source]

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 (Optional[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)[source]

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 | None])[source]

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

Parameters:

values (Iterable[Optional[str]]) – list of strings

See also

addString()

calculateFromVariants(self, values: Iterable[Any])[source]

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[source]

Returns the calculated count of values.

Return type:

int

countDistinct(self) int[source]

Returns the number of distinct string values.

See also

distinctValues()

Return type:

int

countMissing(self) int[source]

Returns the number of missing (null) string values.

Return type:

int

static displayName(statistic: Qgis.StringStatistic) str[source]

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)[source]

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

See also

addString()

majority(self) str[source]

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

Added in version 3.14.

Return type:

str

max(self) str[source]

Returns the maximum (non-null) string value.

Return type:

str

maxLength(self) int[source]

Returns the maximum length of strings.

Return type:

int

meanLength(self) float[source]

Returns the mean length of strings.

Return type:

float

min(self) str[source]

Returns the minimum (non-null) string value.

Return type:

str

minLength(self) int[source]

Returns the minimum length of strings.

Return type:

int

minority(self) str[source]

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

Added in version 3.14.

Return type:

str

reset(self)[source]

Resets the calculated values

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

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

Parameters:

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

See also

statistics()

statistic(self, stat: Qgis.StringStatistic) Any[source]

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[source]

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

See also

setStatistics()

Return type:

Qgis.StringStatistics