Python 通过引用另一个数据帧来提取具有上限的行

Python 通过引用另一个数据帧来提取具有上限的行,python,pandas,dataframe,Python,Pandas,Dataframe,我有这样的数据帧 code Type num a A 3 a A 4 a A 5 a B 6 b A 7 b A 8 c B 9 c C 10 我还有一个数据框,它表示受限代码和类型,以及每个代码和类型的num上限 code Type limit a A 4 b A 7 c C 11 所以我想得到下面的结果 code Type nu

我有这样的数据帧

code  Type  num
a    A     3  
a    A     4 
a    A     5
a    B     6
b    A     7
b    A     8
c    B     9
c    C     10
我还有一个数据框,它表示受限代码和类型,以及每个代码和类型的num上限

code Type limit
a    A    4
b    A    7
c    C    11
所以我想得到下面的结果

code  Type  num
a    A     3  
a    A     4 
a    B     6
b    A     7
c    B     9
c    C     10

如何选择和提取行?

您可以执行
合并
,然后执行
筛选
过程:

df.merge(df1, how="left")[lambda x: x.limit.isnull() | (x.num <= x.limit)].drop("limit", 1)

#code Type  num
#0  a    A    3
#1  a    A    4
#3  a    B    6 
#4  b    A    7
#6  c    B    9
#7  c    C   10

df.merge(df1,how=“left”)[lambda x:x.limit.isnull()|(x.num感谢您的合作!我想知道代码中的'filter()'方法在哪里。我如何应用'filter()'方法?它实际上没有使用
过滤器
。当我说
过滤器
,我指的是这部分:
[lambda x:x.limit.isnull()|(x.num