There has to be an easier way to clean up address data, I hope?

GeoCoding, I need to remove APT# and any number or letter that follows.

This works, but i can not figure out how to include the apt range

This doesnt work and I have no clue what to do

  • In your example, how do you want to deal with cases such as "Apt A", "Apt #9", "APT 1", "APT#9"? – Aaron May 29 '15 at 18:46
  • This is known as address parsing. There are several questions here on the subject that may give you some ideas on how to handle the variety of 'dirty' addresses you may find in your data. I've added the tag which can show you some, as will a search on "address" and "parse" or "parsing". BTW, is the apt number causing the geocoder to fail? I would think it would still find a match, though perhaps with a lower rating. – Chris W May 30 '15 at 7:25
  • I don't care about the cases. The cases do not affect my match rate. The problem is the "APT" and special characters. My street data and address points do not include "apt", "unit", or "#", so this will result as an unmatched record which i will have to fix manually. In this case it was 2000. Thank you for you time!! – Mary May 30 '15 at 8:25

You could give this a try:

!ADDRESS!.lower().split(" apt")[0].strip().title()

for 10221 Yukon Ave Apt#5, it returns: 10221 Yukon Ave

or if you want them all uppercase:

!ADDRESS!.lower().split(" apt")[0].strip().upper()

for 10221 Yukon Ave Apt#5, it returns: 10221 YUKON AVE

Of course this will not work in all situations. For example, if you have a street called 1000 Aptitude Dr, it would mess up and return just 1000. I added a space infront of "apt" for the split. This way it will not fail on, for example, 1000 Captive St.

  • @Mary you may already know this, but you can replace the split(" apt") with split ("#") to alter the addresses that have a # sign, but no apt. – ianbroad May 31 '15 at 8:25
  • of course i will! and yes, i been playing with the expression, im having a blast !! thank you!! – Mary Jun 1 '15 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.