<jupyter_start><jupyter_text>[Getting the Key](https://developers.google.com/maps/documentation/javascript/get-api-key)<jupyter_code>import googlemaps
from datetime import datetime
import simplejson
import urllib, json, time
import pandas as pd
import math
import dateutil 
import datetime as dt
from datetime import datetime, timedelta
apikey = '<KEY>'
df = pd.read_csv('final_top_bikes.csv')
df.info()
def pmam(x):
    x = str(x)
    #x = (':'.join(a+b for a,b in zip(x[::2], x[1::2])))
    if x == 'NaN':
        pass
    try:
        x = str(x[:2] + ':' + x[2:])
        date = dateutil.parser.parse(x)
        return str(date.strftime('%d/%m/%Y %H:%M %p'))
    except:
        return 'NaN'

print(pmam('2017-09-09 07:00:03'))
df['Timestamp index'] = df['Timestamp +2'].apply(pmam)
df['Timestamp index'] = df['Timestamp index'].apply(lambda x: 
                                    dt.datetime.strptime(x,'%d/%m/%Y %H:%M %p'))
df.index = df['Timestamp index']<jupyter_output><empty_output><jupyter_text>From [Stackoverflow](https://stackoverflow.com/questions/36500331/putting-latitudes-and-longitudes-into-a-distance-matrix-google-map-api-in-pytho) and [here](https://developers.google.com/maps/documentation/javascript/get-api-key).<jupyter_code>import urllib, json, time
import pandas as pd

def google(lato, lono, latd, lond):

    url = """https://maps.googleapis.com/maps/api/distancematrix/json?origins=%s,%s"""%(lato, lono)+  \
    """&destinations=%s,%s&mode=bicycling&language=en-EN&sensor=false&key="""+apikey%(latd, lond)
    #print(url)
    #CHANGE THIS FOR PYTHON 3.X TO urllib.request.urlopen(url)...
    response = urllib.request.urlopen(url).read().decode('utf8')

    #Wait a second so you don't overwhelm the API if doing lots of calls
    time.sleep(1)

    obj = json.loads(response)
    try:
        s =   obj['rows'][0]['elements'][0]['duration']['value']
        m = (obj['rows'][0]['elements'][0]['distance']['value'])
        return s, m
    except IndexError:
        #something went wrong, the result was not found
        print (url)
        #return the error code
        return obj['Status'], obj['Status']

def ApplyGoogle(row):
    lato, lono = row['Lat'], row['Long']
    latd, lond = row['newLat'], row['newLong']
    return google(lato, lono, latd, lond)

journeydf['Seconds'], journeydf['Metres'] = zip(*journeydf.apply(ApplyGoogle, axis = 1))<jupyter_output><empty_output><jupyter_text>Space for next analysis<jupyter_code>journeydf.to_csv('data.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17367168913560665, 'fraction_numerical': 0.014274385408406027, 'mean_word_length': 4.056112224448897, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '222037', 'license': 'MIT', 'n_tokens_mistral': 914, 'n_tokens_neox': 880, 'n_words': 178, 'path': '03 google_API_Matrix_data_queries.ipynb', 'repo_name': 'morgulbrut/obike', 'size': '2539'}