3

I am dealing with addresses matching such as 123 Main St. Suite 100 Chicago, IL and 123 Main Street Chicago, IL. One important problem is to transform abbreviations of street type, such as St. to Street. I wonder if there is any Python package that deals with it since it seems like a very common problem for dealing with addresses.

PS, I know usaddress, but it only parses out all the parts, does not do any transformation.

Justin Li
  • 1,035
  • 2
  • 12
  • 19

1 Answers1

3

You can convert to an abbreviation followed by a period by using address and usaddress. I used usaddress since I know it will parse addresses such as 123 S North Dr. This is part of what I did:

import usaddress
from address import AddressParser, Address
addr = usaddress.parse(address_line1)
ad = AddressParser()
addr2 = ad.parse_address(address_line1)
#perform some cleanup and functions on addr...
if addr2.street_suffix:
    post = addr2.street_suffix
else:
    post = ''

Here is the documentation on the address 0.1.1 module.

Update: address does not work in Python 3.x because there is a print function without (). There is another module, street-address documentation here that works similarly for formatting and parsing addresses, but I've found usaddress is sufficient.

For example,

    parser_address = "6400 S FIDDLERS GREEN CIR SUIT 123"
    addr = usaddress.parse(parser_address)

returns:

     [('6400', 'AddressNumber'), ('S', 'StreetNamePreDirectional'), ('FIDDLERS', 'StreetName'), ('GREEN', 'StreetName'), ('CIR', 'StreetNamePostType'), ('SUIT', 'OccupancyType'), ('123', 'OccupancyIdentifier')]
JJ846
  • 41
  • 1
  • 6