I want to iterate through a JSON file and populate a pandas DataFrame via iterating through specific key values of the JSON data.
import pandas as pd
json_data = [
{
"name" : "Brad Green",
"age" : "35",
"address" : {
"street" : "Nicol St. 16",
"city" : "Manhatan"
},
"children" : ["Nati", "Madi"]
},
{
"name" : "Sara Brown",
"age" : "30",
"address" : {
"street" : "Adam St. 66",
"city" : "New York"
},
"children" : "none"
}
]
I don't want to simply add the data from json_data to the df like the code below:
df = pd.DataFrame(json_data, columns=['name', 'address', 'age'])
I wrote a for loop to iterate through the json_data and add the data to df_new:
df_new = pd.DataFrame(columns=['name','age','street','city'])
for i in range(len(json_data)):
df_new = df_new.append({"name": json_data[i]})
...
I know that this for loop obviously can't get the 'name','age','street','city values from json_data but I couldn't manage to find a solution by looking at different posts here. Plus, I want to get the data from address values separately from this nested key value. I would appreciate it if anyone can help me with this issue.