2

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

1 Answer 1

1

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

df = pd.read_json(other_path, orient="records")
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much for responding - I tried that and it still shows the same output as before. Just can;t get it to work.
@John Could you edit your answer to include the input json structure, in a code block at the top?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.