Before trying to read the file, open a few rows in a text editor. In this example, I can see the lines are separated by a newline character.

This means the file is not really a proper JSON file. However, we can still read it in pandas. This file format is generally called JSONL, this means there is a JSON object for each line.

import pandas as pd

file = "https://raw.githubusercontent.com/martinbel/datasets/master/cellphones.json"
df = pd.read_json(file, lines=True)
df.head()

By just passing the lines=True argument to pd.read_json we can read the .jsonl type of file.

If you are interested in learning more about data science, check out my youtube channel!


Leave a Reply

Your email address will not be published. Required fields are marked *