In QGIS 2.18 there is a shapefile with three fields accordingly
I want to get the total sum of all values in the field
"Value". How can I achieve that in the Python Console?
"Value" maintains two types of data
I was trying with a while-loop but it does not work
layer = qgis.utils.iface.activeLayer() if not layer.isValid(): raise Exception('Layer is not valid') features = layer.getFeatures() for feat in features: attr = feat.attributes() if attr == NULL: continue else: total = 0 index = 0 while index < layer.featureCount(): total = total + int(attr) index = index + 1 return(total)
How to achieve one number that gives the total sum of a whole field exclusive
After executing @ahmadhanb's solution I received a correct number but somehow with a strange output type, when
print (type(sum(total)))it gives me
<type 'NoneType'>. What could be a problem?