Saturday, October 4, 2025
HomeLanguagesHow to Read JSON Files with Pandas?

How to Read JSON Files with Pandas?

In this article, we are going to see how to read JSON Files with Pandas.

Reading JSON Files using Pandas

To read the files, we use read_json() function and through it, we pass the path to the JSON file we want to read. Once we do that, it returns a “DataFrame”( A table of rows and columns) that stores data. If we want to read a file that is located on remote servers then we pass the link to its location instead of a local path.

Example 1: Reading JSON file

Python3




import pandas as pd
  
  
df = pd.read_json("FILE_JSON.json")
df.head()


Output:

   One  Two
0   60  110
1   60  117
2   60  103
3   45  109
4   45  117
5   60  102

Example 2: Creating JSON data and reading in dataframe

Here we will create JSON data and then create a dataframe through it using pd.Dataframe() methods.

Python3




import pandas as pd
  
data = {
    "One": {
        "0": 60,
        "1": 60,
        "2": 60,
        "3": 45,
        "4": 45,
        "5": 60
    },
    "Two": {
        "0": 110,
        "1": 117,
        "2": 103,
        "3": 109,
        "4": 117,
        "5": 102
    }
}
  
df = pd.DataFrame(data)
  
print(df)


Output:

   One  Two
0   60  110
1   60  117
2   60  103
3   45  109
4   45  117
5   60  102
RELATED ARTICLES

Most Popular

Dominic
32337 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6706 POSTS0 COMMENTS
Nicole Veronica
11870 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11934 POSTS0 COMMENTS
Shaida Kate Naidoo
6821 POSTS0 COMMENTS
Ted Musemwa
7086 POSTS0 COMMENTS
Thapelo Manthata
6779 POSTS0 COMMENTS
Umr Jansen
6778 POSTS0 COMMENTS