JSON to pandas DataFrame

后端 未结 11 1769
离开以前
离开以前 2020-11-22 05:46

What I am trying to do is extract elevation data from a google maps API along a path specified by latitude and longitude coordinates as follows:

from urllib2         


        
11条回答
  •  清歌不尽
    2020-11-22 06:35

    Just a new version of the accepted answer, as python3.x does not support urllib2

    from requests import request
    import json
    from pandas.io.json import json_normalize
    
    path1 = '42.974049,-81.205203|42.974298,-81.195755'
    response=request(url='http://maps.googleapis.com/maps/api/elevation/json?locations='+path1+'&sensor=false', method='get')
    elevations = response.json()
    elevations
    data = json.loads(elevations)
    json_normalize(data['results'])
    

提交回复
热议问题