In QGIS 2.18 there is a shapefile with three fields accordingly
"id" | "Type" | "Value"
I want to get the total sum of all values in the field
"Value". How can I achieve that in 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)
Moreover, 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?
How to achieve one number that gives the total sum of a whole field exclusive