Skip to content
Related Articles

Related Articles

Improve Article
Load JSON String into Pandas DataFrame
  • Last Updated : 18 Aug, 2020

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 :

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :