Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Using Python in Field calculator to update null values

$
0
0
I am trying to update some entries in an attribute table so that where I have blanks I now have information based on another field in the table using the following code:

def firstupdate(DescGroup, DescTerm):
if (DescGroup in ['Inland Water', 'Tidal Water']) and (DescTerm == <Null>):
return 'Water'
elif (DescGroup in ['Building' , 'Structure' , 'Glasshouse']) and (DescTerm == <Null>):
return 'Structure'
elif (DescGroup in ['Road' , 'Track' , 'Path', 'Rail' , 'Roadside']) and (DescTerm == <Null>):
return 'Track'
else DescTerm == <Null>:
return 'Landform'

My problem is making sure I am recognising Null properly - I have tried with or without quotes as DescTerm is a string field but neither work and I get a syntax error. I have also just tried with using '' rather than the word Null.My attribute table has a field called DescTerm which has some blank entries which I want to update by what is in the DescGroup field. I want all the ones that aren't blank to be left as they are! Any advice on how to do this is much appreciated as this is my first foray into Python!
ps i have also tried doing this just by selecting the blank ones and running an abridged version of the code without the reference to null and I still get a syntax error or it runs and it doesnt actually do anything.

Viewing all articles
Browse latest Browse all 2485

Trending Articles