I am trying to calculate my End_Streets field within two joined tables. I want to remove the redundant SECONDARYN value from the STREETS field.
" & ".join(!IntersectAndEnds2.Streets!.split(" & ").remove(!StreetSplit2.SECONDARYN!))
Here is a portion of my table:
Here is the error I am receiving when I run the expression in the field calculator.
Error typed out:
ERROR 000539: Error running expression: " & ".join(u"ACORN CT & LARAN RD".split(" & ").remove(u"ACORN CT"))
Traceback (most recent call last):
File "", line1, in TypeError Failed to execute (CalculateField)
2 Answers 2
You are trying to join a List.remove (returned from .split()), but a List.remove doesn't return anything, so you'd have to remove the item from the list and then join, or if you want to do it inline, I think this would work to exclude what you don't want:
" & ".join(i for i in !IntersectAndEnds2.Streets!.split(" & ") if i <> !StreetSplit2.SECONDARYN!)
-
And actually my answer doesn't quite work because arcmap thinks the != is a field rather than "not equal".Dan Jurgella– Dan Jurgella2016年05月12日 20:02:59 +00:00Commented May 12, 2016 at 20:02
-
2
-
Thanks. I actually didn't know that Python accepted that.Dan Jurgella– Dan Jurgella2016年05月12日 20:08:10 +00:00Commented May 12, 2016 at 20:08
-
See docs.python.org/release/2.5.2/lib/comparisons.html -
<>
is obsolescent however in this case it works as the!
is signifying something else to arcgis2016年05月12日 20:13:14 +00:00Commented May 12, 2016 at 20:13 -
I have been struggling with this for two days because I'm not a python person. This worked flawlessly. Thank you so much!hherrmann– hherrmann2016年05月12日 20:41:36 +00:00Commented May 12, 2016 at 20:41
If I understand what you're asking, you want to remove the "ACORN CT & " from "ACORN CT & LARAN RD", leaving just "LARAN RD".
Try this expression
!STREETS!.replace("{} & ".format( !SECONDARYN! ), '').replace(" & {}".format( !SECONDARYN! ), '')
which will leave just "LARAN RD".
I am concerned that you are trying to update a joined table. Your table in the screenshot is called StreetSplit2
but in your expression it looks like the Streets
field is in another table called IntersectAndEnds2
. You can't update a joined table using the field calculator, you'd need to calculate that field in the actual table (and if necessary perform the join in the other direction).
-
1I don't think this would not for the case where the SECONDARYN field value is the last road in the list.Richard Fairhurst– Richard Fairhurst2016年05月12日 21:59:35 +00:00Commented May 12, 2016 at 21:59
-
@RichardFairhurst nice spot, have updated around that.2016年05月12日 23:31:25 +00:00Commented May 12, 2016 at 23:31
-
It also would not work for the case where there is no cross street and only the road itself is listed, which can occur for her data since it includes cul-de-sac, stub and dead end points.Richard Fairhurst– Richard Fairhurst2016年05月13日 16:39:32 +00:00Commented May 13, 2016 at 16:39
Explore related questions
See similar questions with these tags.
ACORN CT & LARAN RD
becomesLARAN RD
?