John
John

Reputation: 19

Python - converting a JSON read file into a usable DataFrame

I am new to Python and was trying to use the following code to read in a JSON file and convert it to a dataframe with column headers etc. I just cannot seem to understand what I am doing wrong here as the output is as shown below

import pandas as pd
import matplotlib as plt

other_path = "c:\\users\\xyz\\documents\\covid.json"
df = pd.read_json(other_path)
print (df.head())
print (type (df))

Output

Upvotes: 2

Views: 73

Answers (1)

Eric
Eric

Reputation: 847

Use the argument orient="records" see the docs here

df = pd.read_json(other_path, orient="records")

Upvotes: 1

Related Questions