I'm trying to convert a string column Rainfall
of point layer weather_l
to float:
context = QgsExpressionContext()
context.appendScopes(QgsExpressionContextUtils.globalProjectLayerScopes(weather_l))
num_float = QgsExpression('float(fea["Rainfall"])')
with edit(weather_l):
for fea in weather_l.getFeatures():
context.setFeature(fea)
if not fea['Rainfall'].isalpha():
fea['Rain_D'] = num_float.evaluate(context)
weather_l.updateFeature(fea)
but num_float.evaluate(context)
returns None
. How can I correct
num_float = QgsExpression('float(fea["Rainfall"])')
to convert the string to a float?