Panda dataframe Json flattening for all rows
I have below Panda Dataframe where there are three records.
I am able to do the JSON flattening using only one row at a time, but I try for all rows it doesn't work. JSON flattening for single row.
For all rows I need help as below code is not working at all for me
My Dataframe:
df = pd.DataFrame(
columns=['data'],
data=[
[{ "answers_interface": { "__id": 1, "flags": {}, "heloc": 3 ,"balloon": 4 }}],
[{ "answers_interface": { "__id": 2, "flags": {}, "heloc": 3, "balloon": 4 }}]
])
Convert df['data']
to list, then use json_normalize
:
out = pd.json_normalize(df['data'].tolist())
Output:
answers_interface.__id answers_interface.heloc answers_interface.balloon
0 1 3 4
1 2 3 4