Curriculum
Course: Pandas
Login
Text lesson

Pandas Read JSON

Read JSON

Large datasets are often stored or extracted in JSON format. JSON is plain text with an object structure, widely recognized in programming, including by Pandas. In our examples, we will use a JSON file named ‘data.json’.

Example

Load the JSON file into a DataFrame:

import pandas as pd

df = pd.read_json(‘data.json’)

print(df.to_string()) 
Tip: Use to_string() to display the full DataFrame.

Dictionary as JSON

JSON = Python Dictionary

JSON objects are formatted similarly to Python dictionaries.

If your JSON data is stored in a Python dictionary rather than a file, you can directly load it into a DataFrame.

Example

Load a Python dictionary into a DataFrame:

import pandas as pd

data = {
  “Duration”:{
    “0”:60,
    “1”:60,
    “2”:60,
    “3”:45,
    “4”:45,
    “5”:60
  },
  “Pulse”:{
    “0”:110,
    “1”:117,
    “2”:103,
    “3”:109,
    “4”:117,
    “5”:102
  },
  “Maxpulse”:{
    “0”:130,
    “1”:145,
    “2”:135,
    “3”:175,
    “4”:148,
    “5”:127
  },
  “Calories”:{
    “0”:409,
    “1”:479,
    “2”:340,
    “3”:282,
    “4”:406,
    “5”:300
  }
}

df = pd.DataFrame(data)

print(df)