'Convert Embedded JSON Dictionary to Pandas Dataframe

I have an embedded set of data given to me which needs to be converted to a pandas Dataframe

"{'rows':{'data':[[{'column_name':'column','row_value':value}]]}"

It's just a snippet of what it looks like at the start. Everything inside data repeats over and over. i.e.

{‘column_name’:’name’, ’row_value :value }

I want the values of column_name to be the column headings. And the values of row_value to be the values in each row.

Ive tried a few different ways. I thought it would be something along the lines of

df = pd.DataFrame(data=[data_rows['row_value'] for data_rows in raw_data['rows']['data']], columns=['column_name'])

But I might be way off. I probably not stepping into the data right with raw_data['rows']['data']

Any suggestions would be great.



Solution 1:[1]

You can try to add another loop in your list comprehension to get elements out:

df = pd.DataFrame(data=[data_row for data_rows in raw_data['rows']['data'] for data_row in data_rows])
print(df)

                  name value  type
0  dynamic_tag_tracker  null  null

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ynjxsjmh