Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7875747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:02:50+00:00 2026-06-03T03:02:50+00:00

I am new to Python and I have been cleaning up a messy database

  • 0

I am new to Python and I have been cleaning up a messy database using a combination of Google refine http://code.google.com/p/google-refine/ and Excel, however, I think that Python can do a better job as long as I am able to get some ‘recipes’ that I can reuse.

One variation of my problem is inconsistency in the ‘Location’ field of the database. About 95% of the data has the format in the list Location1, which I have been able to process with python in a more efficient way than with the use of Excel filters. However, I am looking for a python library or recipe that would allow me to work with all types of geo-locations in the database, maybe by defining patterns within the list.

Thanks in advance for your help!

Location1=['Washington, DC','Miami, FL','New York, NY']
Location2=['Kaslo/Nelson area (Canada), BC','Plymouth (UK/England)', 'Mexico, DF - outskirts-, (Mexico),']
Location3=['38.206471, -111.165271']

# This works for about 95% of the data, basically US addresses on Location1 type of List
CityList=[loc.split(',',1)[0] for loc in Location1]
StateList=[loc.split(',',1)[1] for loc in Location1]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:02:51+00:00Added an answer on June 3, 2026 at 3:02 am

    Not sure if you’re still having problems with this but here’s an answer that I believe would work for you:

    #location_regexes.py
    import re
    paren_pattern = re.compile(r"([^(]+, )?([^(]+?),? \(([^)]+)\)")
    
    def parse_city_state(locations_list):
        city_list = []
        state_list = []
        coordinate_pairs = []
        for location in locations_list:
            if '(' in location:
                r = re.match(paren_pattern, location)
                city_list.append(r.group(2))
                state_list.append(r.group(3))
            elif location[0].isdigit() or location[0] == '-':
                coordinate_pairs.append(location.split(', '))
            else:
                city_list.append(location.split(', ', 1)[0])
                state_list.append(location.split(', ', 1)[1])
        return city_list, state_list, coordinate_pairs
    
    #to demonstrate output
    if __name__ == "__main__":
        locations = ['Washington, DC', 'Miami, FL', 'New York, NY',
                    'Kaslo/Nelson area (Canada), BC', 'Plymouth (UK/England)',
                    'Mexico, DF - outskirts-, (Mexico),', '38.206471, -111.165271']
    
        for parse_group in parse_city_state(locations):
            print parse_group
    

    Output:

    $ python location_regexes.py 
    ['Washington', 'Miami', 'New York', 'Kaslo/Nelson area', 'Plymouth', 'DF - outskirts-']
    ['DC', 'FL', 'NY', 'Canada', 'UK/England', 'Mexico']
    [['38.206471', '-111.165271']]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am still new to Python and have been reviewing the following code not
I'm fairly new to Python and have been using Wing IDE to play around
hello im new to python and have been reading over the documentation and am
I am really new to Python and I have been looking for an example
I'm new to Python and I have been trying to search through html with
I am new to Django & Python and have been following a tutorial, but
I have been trying to debug the below python cgi code but doesn't seems
I'm new to python and have been trying to figure this out all day.
I'm new to Python (I have been programming in Java for multiple years now
I am new to python and have been working through the examples in Swaroop

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.