Let's say that I have two tables: people_all
and people_usa
, both with the same structure and therefore the same primary key.
How can I get a table of the people not in the USA?
In SQL I'd do something like:
select a.*
from people_all a
left outer join people_usa u
on a.id = u.id
where u.id is null
What would be the Python equivalent? I cannot think of a way to translate this where statement into pandas syntax.
The only way I can think of is to add an arbitrary field to people_usa (e.g. people_usa['dummy']=1
), do a left join, then take only the records where 'dummy' is nan, then delete the dummy field - which seems a bit convoluted.
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…