Read json file as pandas dataframe?
Using the json module you can parse the json into a python object, then create a dataframe from that:
import json
import pandas as pd
with open('C:/Users/Alberto/nutrients.json', 'r') as f:
data = json.load(f)
df = pd.DataFrame(data)
From your code, it looks like you're loading a JSON file which has JSON data on each separate line. read_json
supports a lines
argument for data like this:
data_df = pd.read_json('C:/Users/Alberto/nutrients.json', lines=True)
Note
Removelines=True
if you have a single JSON object instead of individual JSON objects on each line.