0

I've got a dataframe which has as the following columns:

Site IP     Site Name   Instance    Interface Name  Network Add     Interface IP
20.X.X.1    ROUTER1     VPRN1       interface1      20.49.128.0/17  20.49.208.129   
20.X.X.2    ROUTER2     VPRN1       interface2      20.84.34.0/24   20.84.34.3
20.X.X.3    ROUTER3     VPRN1       interface3      20.84.34.0/24   20.84.34.3
20.X.X.4    ROUTER4     VPRN1       interface4      20.85.51.0/23   20.85.51.1
20.X.X.5    ROUTER5     VPRN1       interface5      20.85.52.0/24   20.85.52.1

And i need to create a new column called "Status", then compare if the IP Addresses are in a overlapped subnet or duplicated like this:

Site IP     Site Name   Instance    Interface Name  Network Add     Interface IP        Status
20.X.X.1    ROUTER1     VPRN1       interface1      20.49.128.0/17  20.49.208.129       OK
20.X.X.2    ROUTER2     VPRN1       interface2      20.84.34.0/24   20.84.34.3          Duplicated
20.X.X.3    ROUTER3     VPRN1       interface3      20.84.34.0/24   20.84.34.3          Duplicated
20.X.X.4    ROUTER4     VPRN1       interface4      20.85.51.0/23   20.85.51.1          Overlapped
20.X.X.5    ROUTER5     VPRN1       interface5      20.85.52.0/24   20.85.52.1          Overlapped

I hope you can help me. thanks a lot. Juan Pablo.

juanpb12
  • 125
  • 1
  • 9

1 Answers1

0

You can do np.select:

df['Status'] = np.select( (df['Network Address'].duplicated(keep=False), 
                           df['Interface IP'].duplicated(keep=False)),
                          ('Duplicated', ‘Overlapped'), 'OK')
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74
  • Quang, thaks for your reply, but the result is not the expected.There are some identified overlapped cases, that indicates OK. And there are not duplicated cases that are shown "duplicated" – juanpb12 Nov 27 '19 at 22:22