
Zachary M. answered 03/01/22
Full Time Software Engineer and Chess Hobbiest
So what you have here would more accurately be defined as a JSON object.
If you want to convert this to a Pandas dataframe, you have to decide how you would want the final dataframe to look.
An excel spreadsheet is a 2 dimensional grid, but this JSON object has many nested levels. Judging by your data, it looks like you have a dictionary where the top level keys are Device Names and the corresponding value for each device name key is a dictionary containing information about that device.
Inside each of these device dictionaries is a dictionary where the keys are Interface Names and the values are dictionaries with information about that interface.
The easiest way to convert this JSON object to a pandas dataframe would be to first convert it to a list of dictionaries, where each dictionary represents a row in the final pandas dataframe. Each dictionary will have a key for each column, and a value for that cell in that column.
The tricky part here is that each interface and each device doesn't always have the same keys inside. So you need to always check to see if the key you are looking for exists and if it doesn't, you fill in a default value.
I don't usually do this but here is the code I wrote to process the data you provided:
Tarik H.
Thanks for your response. I'm curious to know if Pandas json_nomralize is capable to select the required columns directly or does the data still have to be restructured?03/02/22