I'm sorry, I know this question has already been asked, but I haven't managed to optimize/correct my results using the existing help.
I have two pandas dataframe :
df_1 : Contains the whole information bank about switches from 'a' to 'z'
Index localHost localInt vlans
0 switch_a Te1/0/1 100,200,300
1 switch_a Te1/0/2 252,478,963
2 switch_b Te1/0/1 154,586,354
...
df_2 : Miss vlans information for some specific switches (all located in df_1 but not in the same order)
Index localHost localInt vlans
0 switch_a Te1/0/1
1 switch_a Te1/0/2
2 switch_z Te1/0/1
...
I would like to update df_2 or create a new dataframe (doesn't matter much) that will merge the df_1 and df_2 vlans data.
The only condition for the merged is that the localHost and localInt value in the same row are equal in both dataframes when reporting the vlans.
I first tried using a mask to isolate the only relevant rows :
for index, row in df_1.iterrows() :
switch_name = row['localHost']
switch_interface = row['localInt']
switch_vlans = row['vlans']
mask = (df_2['localHost'] == switch_name) & (df_2['localInt'] == switch_interface)
df_2.loc[mask, 'vlans'] = switch_vlans
It seems to be working, but I don't understand why only every other line is processed:
Index localHost localInt vlans
0 switch_a Te1/0/1 100,200,300
1 switch_a Te1/0/2
2 switch_z Te1/0/1 265,477,111
...
Then I tried using a nested loop but the results was the same. do you have any idea what I'm doing wrong? Thanks.