The Wayback Machine - https://web.archive.org/web/20240118173644/https://www.geeksforgeeks.org/load-json-string-into-pandas-dataframe/
Open In App
Related Articles

Load JSON String into Pandas DataFrame

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Let us see how can we use a dataset in JSON format in our Pandas DataFrame. This can be done using the built-in read_json() function. It enables us to read the JSON in a Pandas DataFrame.

Example : Consider the JSON file path_to_json.json :

path_to_json.json




# importing the module
import pandas
  
# reading the file
data = df.read_json("path_to_json.json")
  
# displaying the DataFrame
print(data)


Output :

Now, the final data frame also depends on the type of the JSON file. So there are mainly 3 types of orientations in JSON : 

  • Index Oriented
  • Value-Oriented 
  • Column Oriented

1. Index Oriented

This is an example of an Index Oriented JSON file. 




# importing the module
import pandas
  
# reading the file
data = df.read_json("sample.json")
  
# displaying the DataFrame
print(data)


Output :

2. Value-Oriented

This is an example of a Value-Oriented JSON file.




# importing the module
import pandas
  
# reading the file
data = df.read_json("sample.json")
  
# displaying the DataFrame
print(data)


Output :

3. Column Oriented

This is an example of a Column-oriented JSON file.




# importing the module
import pandas
  
# reading the file
data = df.read_json("sample.json")
  
# displaying the DataFrame
print(data)


Output :


Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills, become a part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 18 Aug, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials