Tarik H.

asked • 02/25/22

Need help for converting nested python dictionary into Pandas dataframe

Hello,

I need help converting data consisting of a nested dictionary into a Pandas data frame that I would like to export to excel.

{"devices": {"Device1": {"interfaces": {"mgmt0": {"oper_status": "up", "ipv4": {"10.216.10.72/24": {"ip": "10.216.10.72", "prefix_length": "24"}}}, "Ethernet1/33": {"oper_status": "up", "port_channel": {"port_channel_int": "Port-channel53"}, "counters": {"in_crc_errors": 0, "in_errors": 0, "in_discard": 0, "out_errors": 0, "out_discard": 0}, "switchport_mode": "trunk", "access_vlan": 1, "trunk_vlans": "10,2101"}, "port-channel53": {"oper_status": "up", "counters": {"in_crc_errors": 0, "in_errors": 0, "in_discard": 0, "out_errors": 0, "out_discard": 0}, "switchport_mode": "trunk", "access_vlan": 1, "trunk_vlans": "10,2101"}, "Vlan2101": {"oper_status": "up", "ipv4": {"192.168.10.1/24": {"ip": "192.168.10.1", "prefix_length": "24"}}}}}, "device2": {"interfaces": {"mgmt0": {"oper_status": "up", "ipv4": {"10.216.10.73/24": {"ip": "10.216.10.73", "prefix_length": "24"}}}, "Ethernet1/47": {"oper_status": "up", "port_channel": {"port_channel_int": "Port-channel100"}, "counters": {"in_crc_errors": 0, "in_errors": 0, "in_discard": 0, "out_errors": 0, "out_discard": 0}, "switchport_mode": "trunk", "access_vlan": 1, "trunk_vlans": "1-4094"}, "Ethernet1/48": {"oper_status": "up", "port_channel": {"port_channel_int": "Port-channel100"}, "counters": {"in_crc_errors": 0, "in_errors": 0, "in_discard": 0, "out_errors": 0, "out_discard": 0}, "switchport_mode": "trunk", "access_vlan": 1, "trunk_vlans": "1-4094"}, "Ethernet1/53": {"oper_status": "up", "counters": {"in_crc_errors": 0, "in_errors": 0, "in_discard": 0, "out_errors": 0, "out_discard": 0}, "switchport_mode": "trunk", "access_vlan": 1, "trunk_vlans": "1-4094"}, "port-channel100": {"oper_status": "up", "counters": {"in_crc_errors": 0, "in_errors": 0, "in_discard": 0, "out_errors": 0, "out_discard": 0}, "switchport_mode": "trunk", "access_vlan": 1, "trunk_vlans": "1-4094"}}}, "Device3": {"interfaces": {"mgmt0": {"oper_status": "up", "ipv4": {"10.216.10.74/24": {"ip": "10.216.10.74", "prefix_length": "24"}}}, "Ethernet1/47": {"oper_status": "up", "port_channel": {"port_channel_int": "Port-channel100"}, "counters": {"in_crc_errors": 0, "in_errors": 0, "in_discard": 0, "out_errors": 0, "out_discard": 0}, "switchport_mode": "trunk", "access_vlan": 1, "trunk_vlans": "1-4094"}, "Ethernet1/48": {"oper_status": "up", "port_channel": {"port_channel_int": "Port-channel100"}, "counters": {"in_crc_errors": 0, "in_errors": 0, "in_discard": 0, "out_errors": 0, "out_discard": 0}, "switchport_mode": "trunk", "access_vlan": 1, "trunk_vlans": "1-4094"}, "Ethernet1/53": {"oper_status": "up", "counters": {"in_crc_errors": 0, "in_errors": 0, "in_discard": 0, "out_errors": 0, "out_discard": 0}, "switchport_mode": "trunk", "access_vlan": 1, "trunk_vlans": "10"}, "port-channel100": {"oper_status": "up", "counters": {"in_crc_errors": 0, "in_errors": 0, "in_discard": 0, "out_errors": 0, "out_discard": 0}, "switchport_mode": "trunk", "access_vlan": 1, "trunk_vlans": "1-4094"}}}, "Device4": {"interfaces": {"mgmt0": {"oper_status": "up", "ipv4": {"10.216.10.75/24": {"ip": "10.216.10.75", "prefix_length": "24"}}}, "Ethernet1/1": {"oper_status": "up", "counters": {"in_crc_errors": 0, "in_discard": 0, "out_discard": 0}, "switchport_mode": "trunk", "access_vlan": 1, "trunk_vlans": "1-4094"}, "Ethernet1/15": {"oper_status": "up", "counters": {"in_crc_errors": 0, "in_errors": 0, "in_discard": 0, "out_errors": 0, "out_discard": 0}, "switchport_mode": "trunk", "access_vlan": 20, "trunk_vlans": "1-4094"}, "Ethernet1/24": {"oper_status": "up", "counters": {"in_crc_errors": 0, "in_errors": 0, "in_discard": 0, "out_discard": 0}, "switchport_mode": "trunk", "access_vlan": 1, "trunk_vlans": "1-4094"}, "Ethernet1/47": {"oper_status": "up", "counters": {"in_crc_errors": 0, "in_discard": 0, "out_discard": 0}, "switchport_mode": "trunk", "access_vlan": 1, "trunk_vlans": "1-4094"}, "Ethernet1/53": {"oper_status": "up", "counters": {"in_crc_errors": 0, "in_errors": 0, "in_discard": 0, "out_discard": 0}, "switchport_mode": "trunk", "access_vlan": 1, "trunk_vlans": "1-4094"}, "Vlan5": {"oper_status": "up", "ipv4": {"10.216.43.11/24": {"ip": "10.216.43.11", "prefix_length": "24"}}}, "Vlan10": {"oper_status": "up", "ipv4": {"10.216.42.1/24": {"ip": "10.216.42.1", "prefix_length": "24"}}}, "Vlan20": {"oper_status": "up", "ipv4": {"10.216.20.1/24": {"ip": "10.216.20.1", "prefix_length": "24"}}}, "Vlan100": {"oper_status": "up", "ipv4": {"10.249.128.2/30": {"ip": "10.249.128.2", "prefix_length": "30"}}}, "Vlan101": {"oper_status": "up", "ipv4": {"10.249.128.6/30": {"ip": "10.249.128.6", "prefix_length": "30"}}}, "Vlan102": {"oper_status": "up", "ipv4": {"10.249.128.10/30": {"ip": "10.249.128.10", "prefix_length": "30"}}}, "Vlan103": {"oper_status": "up", "ipv4": {"10.249.128.14/30": {"ip": "10.249.128.14", "prefix_length": "30"}}}}}, "Device5": {"interfaces": {"mgmt0": {"oper_status": "up", "ipv4": {"10.216.10.76/24": {"ip": "10.216.10.76", "prefix_length": "24"}}}}}}}

The output into excel should be similar to this:

https://paste.pics/G68D2

Thank you for your assitance

1 Expert Answer

By:

Zachary M. answered • 03/01/22

Tutor
5 (8)

Full Time Software Engineer and Chess Hobbiest

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?
Report

03/02/22

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.