Posts

Showing posts with the label JSON Data Read multiple ways

Machine Learning - Reading the JSON data using Python in 3 ways

Image
  Dear Learners, This blog is to just give a glimpse to show how a simple python code can be used to extract the data from Web API(JSON ) into a tabular (pandas) format. As a learner myself had experienced many hurdles to find out the ways to read JSON effectively therefore blogging here to share my approaches to the problem .For further references , please visit my Git link given below and also i have shared my Linked In profile and Youtube Channel. Here are the 3 different ways to do it : Approach 1 : #Importing Python Libraries import requests import pandas as pd from pandas.io.json import json_normalize #used this example URL for example json url = 'https://api.github.com/repos/pandas-dev/pandas/issues' resp = requests.get(url) resp #Read the JSON data = resp.json() #Declare a  Dict Variable data_flat = {} #Define the Custom Function Named flatten_dict which is resposible to flatten the JSON: def flatten_dict(obj,name=''):     for k,v in obj.items():