Python - Processing JSON Data

Neha Kumawat

a year ago

JSON file stores data as text in human-readable format. JSON stands for JavaScript Object Notation. Pandas can read JSON files using the read_json function.

Input Data

Create a JSON file by copying the below data into a text editor like notepad. Save the file with .json extension and choosing the file type as all files(*.*).

   "ID":["1","2","3","4","5","6","7","8" ],
   "Name":["Rick","Dan","Michelle","Ryan","Gary","Nina","Simon","Guru" ]
   "Salary":["623.3","515.2","611","729","843.25","578","632.8","722.5" ],
   "StartDate":[ "1/1/2012","9/23/2013","11/15/2014","5/11/2014","3/27/2015","5/21/2013",
   "Dept":[ "IT","Operations","IT","HR","Finance","IT","Operations","Finance"]

Read the JSON File

The read_json function of the pandas library can be used to read the JSON file into a pandas DataFrame.

import pandas as pd

data = pd.read_json('path/input.json')
print (data)
When we execute the above code, it produces the following result.

Submit Review

We're Online!

Chat now for any query