0

Good afternoon, I am new to programming, I would like to ask you for help with the following: I have two DataFrames df1 and df2

df1 is composed of the following registers:

ID Nombre Teléfono
C0001 ANTONIO 345
C0002 LAURA 326
C0003 CAMILO 289
C0004 JOSE 245

df2 is made up of these other registers:

ID Nombre Teléfono
C0001 ANTONIO 345
C0002 LAURA 326
C0003 CAMILO 289
C0004 JOSE 245
C0005 NATALIA 345
C0006 ERIKA 326
C0007 LINA 289
C0008 CRISTINA 245

I want to get a third df3 in this way which only contains the records where ID is unique

ID Nombre Teléfono ``
C0005 NATALIA 345
C0006 ERIKA 326
C0007 LINA 289
C0008 CRISTINA 245

I use the isin() method

x=df1.ID.isin(df2.ID)

but it shows the following, I would like to know how I can take the records that are false and show their information: 0 True 1 True 2 True 3 True 4 False 5 False 6 False 7 False

I need to get this result:

ID Nombre Teléfono
C0005 NATALIA 345
C0006 ERIKA 326
C0007 LINA 289
C0008 CRISTINA 245
0

1 Answer 1

1

Combine Series.isin with the unary ~ operator to invert the boolean values, and use the series to select from df2:

df2[~df2.ID.isin(df1.ID)] ID Nombre Teléfono 4 C0005 NATALIA 345 5 C0006 ERIKA 326 6 C0007 LINA 289 7 C0008 CRISTINA 245 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.