I am trying to find a way to look for the missing data in dataframe based on the data in my list. Each interface must have this 5 sub-interfaces.
sub_interface_list = ['1030', '1035', '1039', '1050', '1059']
df = pd.DataFrame({'Device': ['DeviceA', 'DeviceA', 'DeviceA', 'DeviceA', 'DeviceA', 'DeviceA', 'DeviceA', 'DeviceA', 'DeviceA'], 'Interface': ['Eth-Trunk100', 'Eth-Trunk100', 'Eth-Trunk100', 'Eth-Trunk100', 'Eth-Trunk100', 'Eth-Trunk101', 'Eth-Trunk101', 'Eth-Trunk101', 'Eth-Trunk101'], 'Sub_interface': ['1030', '1035', '1039', '1050', '1059', '1030', '1039', '1050', '1059']})
The dataframe looks like this
Device Interface Sub_interface
DeviceA Eth-Trunk100 1030
DeviceA Eth-Trunk100 1035
DeviceA Eth-Trunk100 1039
DeviceA Eth-Trunk100 1050
DeviceA Eth-Trunk100 1059
DeviceA Eth-Trunk101 1030
DeviceA Eth-Trunk101 1039
DeviceA Eth-Trunk101 1050
DeviceA Eth-Trunk101 1059
From the list we can see that Eth-Trunk101 is missing the sub_interface of 1035, and I would like to insert the 1035 into the last row of each interface. I know using dataframe.iterrows() and search for the missing element is easy, but is there any way in pandas that can be used without using the for loop?
** This is a test data set, my data is much bigger and using iteration will be very time consuming.
df? It may be a better option to insert this prior to creating thedf?