Python uses an open-source package Pandas. With it, we can easily read and analyze large datasets.
By using the read_json()
function and importing the Pandas package, we can easily read a JSON file and display its data in a
read_json(path)
This method takes the parameter, path
, which represents the file path or directory.
It returns JSON data as DataFrame or series.
{"Names":{"0":"Amelia Jacob","1":"Samantha Kyle","2":"Isabella Elizabeth","3":"Rhys Amelia","4":"James Sarah","5":"Olivia Poppy"},"Hobbies":{"0":"NovelReading","1":"Cricket","2":"Painting","3":"Football","4":"Cooking","5":"Gaming"},"Age":{"0":25,"1":20,"2":23,"3":19,"4":23,"5":12}}
pd
alias.mydataframe
, in which the data.json
file is loaded with the help of the read_json()
function.to_string()
to display all the data present in the JSON file.We can store any type of data we want to store in this file. In this case, we are storing demo data.
"Names"
represents the columns of the data frame. Similarly, "Hobbies"
and "Age"
are also representing the other columns of the resultant data frame.
The numbers included inside the brackets {"0"
, "1"
, and so on} represent the index number. By convention, DataFrame always starts at the index 0
. Therefore, the first entry will be at the 0
index.