0

I have two data frames A and B with columns, [a,b,c] and [c,d,f] respectively. I want to select the column 'a' from data-frame A, such that the elements of column 'c' are present in A, but not in B. How would I got about it?

Something like the sql equivalent of, 'Select a from A such that c in A and c not in B'

Thanks!

Nikki
  • 3
  • 4
  • You should post the data frames along with an example of the desired output. (You will have to do it manually) – James Schinner Feb 06 '18 at 15:20
  • have you tried iterating thru rows and comparing using basic python operations, as described in this post? https://stackoverflow.com/questions/7837722/what-is-the-most-efficient-way-to-loop-through-dataframes-with-pandas – cptwonton Feb 06 '18 at 15:20
  • @cptwonton, I would like to avoid iterating through due to the slow performance. – Nikki Feb 06 '18 at 15:23

1 Answers1

0

This may be what you are looking for:

 A_filtered = A.loc[~A['c'].isin(set(B['c'])), 'a']

The pandas Indexing and Selecting Data documentation has more detail on the syntax.

jpp
  • 159,742
  • 34
  • 281
  • 339