Hi,
I've tried a few examples giving to people asking a similar question , but haven't managed to get any of them to work using the field calculator.
I basically have a shapefile with a field named "d_material" which contains the following entries:
DI - Ductile Iron
HDPE - High Density Polyethylene
HPPE - High Performance Polyethylene
CI - Cast Iron
MDPE - Medium Density Polyethylene
SI - Spun Iron
uPVC - Unplasticised Poly Vinyl Chloride
It also contains Null/blank cells
I'm trying to use the field calculator to remove text so I only end up with:
DI
HDPE
HPPE
CI
MDPE
SI
uPVC
Blank fields stay blank
I know its possible, but haven't managed to get it working. Any help would be great thanks. I'm running ArcMap v10.2.1 for desktop.
Regards,
Thomas
Solved! Go to Solution.
The logic I think you are looking for
a = ['DI - Ductile Iron', None, 'HDPE - High Density Polyethylene',
'HPPE - High Performance Polyethylene', 'CI - Cast Iron',
'MDPE - Medium Density Polyethylene', None, 'SI - Spun Iron',
'uPVC - Unplasticised Poly', 'Vinyl Chloride']
def cal(i):
if i is None:
v = None
else:
v = i.split(' ')[0]
return v
for i in a:
print(cal(i))
DI
None
HDPE
HPPE
CI
MDPE
None
SI
uPVC
Vinyl
The logic I think you are looking for
a = ['DI - Ductile Iron', None, 'HDPE - High Density Polyethylene',
'HPPE - High Performance Polyethylene', 'CI - Cast Iron',
'MDPE - Medium Density Polyethylene', None, 'SI - Spun Iron',
'uPVC - Unplasticised Poly', 'Vinyl Chloride']
def cal(i):
if i is None:
v = None
else:
v = i.split(' ')[0]
return v
for i in a:
print(cal(i))
DI
None
HDPE
HPPE
CI
MDPE
None
SI
uPVC
Vinyl
Or something like this....
if s is not None:
print s[:s.index('-')]
else:
print ' '
Thanks guys this was a gret help. I got it working