AnsweredAssumed Answered

Field Calculator - Diameter conversion with conditions

Question asked by TADanks on Dec 11, 2017
Latest reply on Dec 12, 2017 by tkowal


I am very new with python so have been really struggling with the field calculator for what seems like a simple task. (it is in excel anyway)

I have a shapefile with a column named d_diameter, but this column is String and contains entires; 100mm, 2in,4in, 70in, 50mm, 73mm etc. I am looking to convert these to numbers, specifically to milimeters (mm) and to 2 decimal points.


So ones with "mm" extension, I just want the number. Entries with the "in" extension in I want this removed and the value timesed (*) by 25.4 to convert it to mm.

e.g. 100mm becomes 100 and 2in becomes 50.8 etc


The kicker is sometimes it has NULL values, or Text "Other" or "Unknown". Ideally I want in these cases for it to come through as NULL.

Any idea or input where to start would be greatly appreciated.