Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. def replace_street_abbreviations_with_full_name(street_str):
  2.     """
  3.    Returns the string with street abbreviations (e.g., "Ave") replaced with their full street name (e.g., "Avenue")
  4.  
  5.    Keyword arguments:
  6.    street_str : string that corresponds to the CSV's file column 'Street'
  7.    """
  8.    
  9.     abbreviation_to_full_dict = {r'\bAve\b': "Avenue",
  10.                                 r'\bDr\b': "Drive",
  11.                                 r'\bBlvd\b': "Boulevard",
  12.                                 r'\bSt\b': "Street",
  13.                                 r'\bRd\b': "Road",
  14.                                 r'\bPl\b': "Plaza",
  15.                                 r'\bCt\b': "Court",
  16.                                 r'\bHwy\b': "Highway"}
  17.  
  18.    
  19.     for abbreviation, full in abbreviation_to_full_dict.items():
  20.         street_str = re.sub(abbreviation, full, street_str, flags=re.IGNORECASE)
  21.  
  22.     return street_str
  23.  
  24. data_frame['Street'] = data_frame['Street'].apply(lambda row: replace_street_abbreviations_with_full_name(row))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement