0

I need to check if the elements from 'a' are contained in 'b', and save in another vector the elements that are different.

In R, I do as follows:

a <- df$v1
b <- df2$v1
c <- a[!(a %in% b)]

How can I do the same thing in Python? I tried to use (a-b), but the result returned the difference of element values. I would not like that, I would like to retrieve elements that are different from 'a' to 'b'.

Regards, Thaciana

cs95
  • 379,657
  • 97
  • 704
  • 746
  • Hold on, you say vectors but your title says sets... Those are usually quite distinct data types. Can you clarify exactly what you are trying to do? It sounds like you are working with `numpy` given your description of what `a - b` did, but you haven't given us any other clue as to what `a` and `b` are... – juanpa.arrivillaga May 26 '18 at 20:00
  • Sorry. For example, a = [123, 526, 897] and b = [123, 526, 987, 256, 124, 789, 258]. All elements are ids and a is a subset of b. So, I want to retrieve all the different ids of b that are not in the a and save in c. – Thaciana G O Cerqueira May 26 '18 at 22:51
  • But if that were the case, then `a - b` would give an error. – juanpa.arrivillaga May 27 '18 at 05:47
  • yes, a - b do not give the correct value. I would like to know another way to do it, where I can get all the values in b that are different from a and add in c. – Thaciana G O Cerqueira May 27 '18 at 20:47

0 Answers0