1

I am querying AD for a list of machines. I filter this list with pandas by last log on date. When I am done with this data I have one column in a dataframe.

I have another report that has a list of machines that a product we use is installed. I clean this data and I am left with the devices that I want to use to compare to the AD data. Which is just one column in a dataframe.

I have also tried comparing list to list. I am not sure on the best the method.

I tried the merge but my guess this compares DF1 row 1 to DF2 row 1.

DF1 = comp1,comp2,comp3,comp5

DF2 = comp1,comp2,comp3

How would I check each row in DF1 to make sure that each value in DF2 exist and return true or false?

I am trying to figure out machines in DF1 that don't exist in DF2.

1 Answers1

0

DataFrame.isin

this is a simple check to see if one value is in another, you do this in a multitude of ways, this is probably one of the simpliest.

I'm providing some dummy data but please check out How to make good reproducible pandas examples

machines = ['A','B','C']
machines_to_check = ['A','B']

df = pd.DataFrame({'AD' : machines})

df2 = pd.DataFrame({'AD' : machines_to_check})

now, if we want to check for the machines that exist in df but not in df2 we can use ~ which inverts the .isin function.

non_matching_machines = df.loc[~df['AD'].isin(df2['AD'])]
print(non_matching_machines)
    AD
2   C
Umar.H
  • 22,559
  • 7
  • 39
  • 74