Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Data preprocessing
  • Data Manipulation
  • Data Analysis using Pandas
  • EDA
  • Pandas Exercise
  • Pandas AI
  • Numpy
  • Matplotlib
  • Plotly
  • Data Analysis
  • Machine Learning
  • Data science
Open In App
Next Article:
Convert CSV to Pandas Dataframe
Next article icon

Convert JSON to Pandas DataFrame

Last Updated : 13 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

When working with data, it's common to encounter JSON (JavaScript Object Notation) files, which are widely used for storing and exchanging data. Pandas, a powerful data manipulation library in Python, provides a convenient way to convert JSON data into a Pandas data frame. In this article, we'll explore how to convert JSON data into a Pandas DataFrame, covering various scenarios and options you might encounter along the way.

Pandas library is used to work with the data frames and manipulate the data frames. we can read data from various files with the help of pandas .

  • Importing the pandas Library.
  • Reading the JSON file.
  • Converting into data frame .
  • Printing the data frame.

Pandas Convert JSON to DataFrame

Importing the pandas

This is the first step to working with the data frames in Pandas. First, we import Panda's library from Python. To convert a file to the data frame, we need to have a JSON file to perform that operation. First, we will create a JSON file or we will just download a Json file.

For importing the pandas library in python we need to use the import statement:

Python
import pandas as pd  

Using json Module to create a file

Here, we will create a sample json file here the json file is as shown below .

Python
import json  data = {     "Name": {         "0": "Harsha",         "1": "Vardhan",         "2": "Krishna",         "3": "Hanuman",         "4": "Shiva"     },     "Roll_no": {         "0": 1,         "1": 2,         "2": 3,         "3": 4,         "4": 5     },     "subject": {         "0": "C",         "1": "JAVA",         "2": "C++",         "3": "SWIFT",         "4": "PYTHON"     } }  with open('subject.json', 'w') as json_file:     json.dump(data, json_file, indent=4) 
  • In the above code we have created a json file and the json file consists of key value pair.
  • The data is stored in the form of strings as a keys and values as a list .
  • We will read the json file with the help of the read_json() to read the contents of the file .

Converting into DataFrame :

Python
#Importing the pandas Library  import pandas as pd  #Reading the JSON File  dataFrame = pd.read_json("subject.json") #Printing the data Frame print(dataFrame) 

Output :

        Name      Roll_no   subject 
0 Harsha 1 C
1 Vardhan 2 JAVA
2 Krishna 3 C++
3 Hanuman 4 SWIFT
4 Shiva 5 PYTHON

Now, we will implement the same on a downloaded dataset,


Next Article
Convert CSV to Pandas Dataframe
author
boora_harsha_vardhan
Improve
Article Tags :
  • Python
  • Pandas
  • Python-pandas
  • Python pandas-dataFrame
  • Python-json
  • AI-ML-DS With Python
Practice Tags :
  • python

Similar Reads

  • Convert CSV to Pandas Dataframe
    In this article, we will discuss how to convert CSV to Pandas Dataframe, this operation can be performed using pandas.read_csv reads a comma-separated values (csv) file into DataFrame. Example 1: In the below program we are going to convert nba.csv into a data frame and then display it. [GFGTABS] Py
    1 min read
  • Pyspark - Converting JSON to DataFrame
    In this article, we are going to convert JSON String to DataFrame in Pyspark. Method 1: Using read_json() We can read JSON files using pandas.read_json. This method is basically used to read JSON files through pandas. Syntax: pandas.read_json("file_name.json") Here we are going to use this JSON file
    1 min read
  • Convert Bytes To a Pandas Dataframe
    In Python, bytes are a built-in data type used to represent a sequence of bytes. They are immutable sequences of integers, with each integer typically representing a byte of data ranging from 0 to 255. Convert Bytes Data into a Python Pandas Dataframe?We can convert bytes into data frames using diff
    4 min read
  • How to Convert Pandas DataFrame into a List?
    In this article, we will explore the process of converting a Pandas DataFrame into a List, We'll delve into the methods and techniques involved in this conversion, shedding light on the versatility and capabilities of Pandas for handling data structures in Python. Ways to convert Pandas DataFrame In
    7 min read
  • How to convert Dictionary to Pandas Dataframe?
    Converting a dictionary into a Pandas DataFrame is simple and effective. You can easily convert a dictionary with key-value pairs into a tabular format for easy data analysis. Lets see how we can do it using various methods in Pandas. 1. Using the Pandas ConstructorWe can convert a dictionary into D
    2 min read
  • Convert JSON data to Dataframe in R
    In Data Analysis, we have to manage data in various formats, one of which is JSON (JavaScript Object Notation). JSON is used for storing and exchanging data between different systems and is hugely used in web development. In R Programming language, we have to work often with data in different format
    4 min read
  • How to Convert Pandas to PySpark DataFrame ?
    In this article, we will learn How to Convert Pandas to PySpark DataFrame. Sometimes we will get csv, xlsx, etc. format data, and we have to store it in PySpark DataFrame and that can be done by loading data in Pandas then converted PySpark DataFrame. For conversion, we pass the Pandas dataframe int
    3 min read
  • How to convert pandas DataFrame into JSON in Python?
    JSON (JavaScript Object Notation) is a lightweight, easily readable format widely used for data interchange between applications, making it ideal for sharing data across different systems. With Pandas, converting a DataFrame into JSON is simple and efficient using the to_json() function. This articl
    7 min read
  • Converting Django QuerySet to Pandas DataFrame
    Django's ORM provides a powerful way to query databases and retrieve data using QuerySet objects. However, there are times when you may need to manipulate, analyze, or visualize this data in a more sophisticated way than what Django alone can offer. In such cases, pandas, a popular data manipulation
    6 min read
  • Python - Convert dict of list to Pandas dataframe
    In this article, we will discuss how to convert a dictionary of lists to a pandas dataframe. Method 1: Using DataFrame.from_dict() We will use the from_dict method. This method will construct DataFrame from dict of array-like or dicts. Syntax: pandas.DataFrame.from_dict(dictionary) where dictionary
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences