首页 > 解决方案 > Python 等效于 select * from a where account_id in (select account_id from b)

问题描述

正如标题所示。我来自 SQL 背景,正在寻找最好的方法。

c = a.account_id.isin(b.account_id).astype(bool) 
a[c]

以上是最有效的方法吗?

标签: pythonpandas

解决方案


是的,但是我们可以将它们放入 on row 中,并且您不需要将isin输出转换为 bool,因为它已经是 bool 类型的数据

a[a.account_id.isin(b.account_id)]

推荐阅读