JSON to pandas DataFrame

后端 未结 11 1727
离开以前
离开以前 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:32

    Here is small utility class that converts JSON to DataFrame and back: Hope you find this helpful.

    # -*- coding: utf-8 -*-
    from pandas.io.json import json_normalize
    
    class DFConverter:
    
        #Converts the input JSON to a DataFrame
        def convertToDF(self,dfJSON):
            return(json_normalize(dfJSON))
    
        #Converts the input DataFrame to JSON 
        def convertToJSON(self, df):
            resultJSON = df.to_json(orient='records')
            return(resultJSON)
    

提交回复
热议问题