如何根据其他数据框的条件删除熊猫组

我有两个数据框,看起来像这样

df1 =
   name   color
0  John   Blue
1  John   Red
2  Lucy   Green
3  Lucy   Blue
4  Max    Blue
2  Max    White

df2 =
   name   value
0  John   15
1  Lucy   20
2  Max    5

I am trying to drop all the grouped names in df1 whose value in df2 is below 10 (in this case, I would want to drop all the rows with df1['name']='Max').

我想要得到的结果是:

df1 =
   name   color
0  John   Blue
1  John   Red
2  Lucy   Green
3  Lucy   Blue

谢谢!

评论
gvel
gvel

像这样:

In [731]: res = pd.merge(df1, df2, on='name')
In [736]: res[res['value'].ge(10)][['name','color']]

Out[736]: 
   name  color
0  John   Blue
1  John    Red
2  Lucy  Green
3  Lucy   Blue
点赞
评论
浅唱夜旳美
浅唱夜旳美

df1['name'].isin(['Max']) # select the df1 which name is 'Max'

df1=df1[~df1['name'].isin(['Max'])] # reverse select the other elements.

点赞
评论