相关疑难解决方法(0)

使用pandas组内的多个条件检查值是否存在

以下是我的数据框的样子。Expected_Output是我想要的/目标列。

   Group  Value1  Value2  Expected_Output
0      1       3       9             True
1      1       7       6             True
2      1       9       7             True
3      2       3       8            False
4      2       8       5            False
5      2       7       6            False
Run Code Online (Sandbox Code Playgroud)

如果任何 Value1 == 7 AND如果在给定内有任何 ,那么我想返回。Value2 == 9GroupTrue

我试过无济于事:

df['Expected_Output']= df.groupby('Group').Value1.isin(7) &  df.groupby('Group').Value2.isin(9)
Run Code Online (Sandbox Code Playgroud)

注意:- 可以输出真/假或 1/0。

python numpy pandas

6
推荐指数
1
解决办法
4164
查看次数

标签 统计

numpy ×1

pandas ×1

python ×1