0

I have the following part of a JSON file:

[{"Date":"2020-02-17","Rt_low":0.5,"Rt_avg":1.93,"Rt_up":4,"population":"hosp"},{"Date":"2020-02-18","Rt_low":0,"Rt_avg":1.74,"Rt_up":4,"population":"hosp"}]

I want to read this in Python Pandas as a dataframe with the 4 columns as headers:

L = ['Date','Rt_low','Rt_up','population']

I tried the following:

df = pd.DataFrame(pd.read_json(file_name, lines=True))

Which gives me a [1 rows x 235 columns] for the whole dataset. I want to get 4 columns dataframe. How do I do this?

2 Answers 2

1

you may try this approach.

import pandas as pd
dataframe = pd.read_json('sample_json_file.json', orient='values')
print(dataframe)

output for the final dataframe will be one that consists of a header row, and two observations.

Sign up to request clarification or add additional context in comments.

Comments

0

I just did by:

df = pd.DataFrame(pd.read_json(file_name))

Comments

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.