等同于"in". pandas 中的关键字或子查询 [英] Equivalent of "in" keyword or subquery in pandas

查看:82
本文介绍了等同于"in". pandas 中的关键字或子查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Series对象(我们称其为MySeries),其中包含一个整数列表.

I have a Series object (let's call this MySeries) which contains a list of integers.

我还有一个单独的数据框(例如MyDataFrame),其中包括一个称为MyField的列/字段.

I also have a separate dataframe (say MyDataFrame), which includes a column/field called MyField.

我想从MyDataFrame中选择MyField中的值位于MySeries

I want to select all records from MyDataFrame where the value in MyField is in MySeries

等效的SQL将是:

Select * from MyDataFrame 
where MyField in 
    (select * from MySeries)

有人可以建议最好的方法吗?

Could anyone suggest the best way to do this?

非常感谢您的帮助.

推荐答案

,您可以使用因此,首先您将获得钳工系列:

so, first you get fiter Series:

>>> df['A'].isin(f)
0     True
1     True
2    False
3    False
4    False

然后使用它来过滤您的DataFrame

And then use it to filter your DataFrame

这篇关于等同于"in". pandas 中的关键字或子查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆