Search code examples
pythonreplacesplitstreet-address

Python .replace 'st' with 'street' but leave street name the same


I'm trying to change st. to street, ave. to avenue, etc. using .replace() for addresses in a single cell. For example: WEST ST. should be WEST STREET or MOUNT PEBBLE RD. should be MOUNT PEBBLE ROAD

Here is my code:

if 'STREET' not in address and address.find('ST.'):
    address = address.replace('ST','STREET')

The result gives me WESTREET STREET. How can I leave the address name untouched without altering the address name? I tried .split() but most cells had different list lengths so it got really confusing.


Solution

  • Try this:

    if 'STREET' not in address and address.find('ST.'):
        address = address.replace(' ST.',' STREET')