Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def replace_street_abbreviations_with_full_name(street_str):
- """
- Returns the string with street abbreviations (e.g., "Ave") replaced with their full street name (e.g., "Avenue")
- Keyword arguments:
- street_str : string that corresponds to the CSV's file column 'Street'
- """
- abbreviation_to_full_dict = {r'\bAve\b': "Avenue",
- r'\bDr\b': "Drive",
- r'\bBlvd\b': "Boulevard",
- r'\bSt\b': "Street",
- r'\bRd\b': "Road",
- r'\bPl\b': "Plaza",
- r'\bCt\b': "Court",
- r'\bHwy\b': "Highway"}
- for abbreviation, full in abbreviation_to_full_dict.items():
- street_str = re.sub(abbreviation, full, street_str, flags=re.IGNORECASE)
- return street_str
- 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