Class: QgsStringStatisticalSummary

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

Bases: sip.wrapper

Constructor for QgsStringStatistics

Parameters:stats – 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 via setStatistics().

New in version 2.16: Enums

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.
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.
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.

Signals

Attributes

All
Count
CountDistinct
CountMissing
Max
MaximumLength
MeanLength
Min
MinimumLength
All = 255
Count = 1
CountDistinct = 2
CountMissing = 4
Max = 16
MaximumLength = 64
MeanLength = 128
Min = 8
MinimumLength = 32
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 – 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 – 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 – list of strings

See also

addString()

calculateFromVariants(self, values: List[Any])

Calculates summary statistics for an entire list of variants at once. Any non-string variants will be ignored.

Parameters:values – list of variants

See also

calculate()

See also

addValue()

count(self) → int

Returns the calculated count of values.

countDistinct(self) → int

Returns the number of distinct string values.

See also

distinctValues()

countMissing(self) → int

Returns the number of missing (null) string values.

displayName(statistic: QgsStringStatisticalSummary.Statistic) → str

Returns the friendly display name for a statistic

Parameters:statistic – statistic to return name for
distinctValues(self) → Set[str]

Returns the set of distinct string values.

See also

countDistinct()

finalize(self)

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

See also

addString()

max(self) → str

Returns the maximum (non-null) string value.

maxLength(self) → int

Returns the maximum length of strings.

meanLength(self) → float

Returns the mean length of strings.

New in version 3.0.

min(self) → str

Returns the minimum (non-null) string value.

minLength(self) → int

Returns the minimum length of strings.

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 – flags for statistics to calculate

See also

statistics()

statistic(self, stat: QgsStringStatisticalSummary.Statistic) → Any

Returns the value of a specified statistic

Parameters:stat – statistic to return
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

setStatistics()