Reputation: 841
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?
Upvotes: 0
Views: 1626
Reputation: 121
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.
Upvotes: 1