0

I am trying to do reverse geocoding and extract pincodes for lot-long. The .csv file has around 1 million records..

Below is my problem

1. Google API failing to give address for large records, and taking huge amount of time. I will later move it to Batch-Process though.
2. I tried to split the file into chunks and ran few files manually one by one (1000 records in each file after splitting), then i surprisingly get 100% result.
3. Later, I ran in loop one by one, again, Google API fails to give the result

Note: Right now we are looking for free API's only

**Below is my code**
def reverse_geocode(latlng):
    result = {}
    url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng={}'    
    request = url.format(latlng)              
    key= '&key=' + api_key
    request = request + key       
    data = requests.get(request).json()   
    if len(data['results']) > 0:
        result = data['results'][0]
    return result
def parse_postal_code(geocode_data):
    if (not geocode_data is None) and ('formatted_address' in geocode_data):
       for component in geocode_data['address_components']:
            if 'postal_code' in component['types']:
                return component['short_name']
    return None

dfinal = pd.DataFrame(columns=colnames)
dmiss = pd.DataFrame(columns=colnames)

for fl in files:
    df = pd.read_csv(fl)
    print ('Processing file : '  + fl[36:]) 
    df['geocode_data'] = ''        
    df['Pincode'] = ''  
    df['geocode_data']=df['latlng'].map(reverse_geocode)
    df['Pincode'] = df['geocode_data'].map(parse_postal_code)
    if (len(df[df['Pincode'].isnull()]) > 0):
        d0=df[df['Pincode'].isnull()]
        print("Missing Picodes : " + str(len(df[df['Pincode'].isnull()])) + " / " + str(len(df)))
        dmiss.append(d0)
        d0=df[~df['Pincode'].isnull()]
        dfinal.append(d0)
    else:
        dfinal.append(df)

Can anybody help me out, what is the problem in my code? or if any additional info required please let me know....

1 Answer 1

1

You've run into Google API usage limits.

Sign up to request clarification or add additional context in comments.

1 Comment

Thats right.. i have to break the calling function to check... and got "Time Limit Error".. thanks Ervin!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.