根据组过滤唯一值

时间:2018-10-04 20:29:12

标签: python python-3.x pandas dataframe

我有下表:

And the user fills the field email with 'myEmail@email.com' on the 'signUp' page

And the user fills the field email with 'myEmail@email.com' on the 'signIn' page'

我想过滤掉id L1 L2 1 A B 1 A C 1 A D 1 B B 1 B C 1 B D 2 D A 2 D F 中的任何L2值,但只能在同一L1组中。因此,对于id,我们过滤掉id=1,但保留L2=B。对于L2=D,我们保留id=2

输出应类似于:

L2=A

1 个答案:

答案 0 :(得分:0)

我将假设您正在使用pandas

df.groupby('id').apply(lambda x: x[~x.L2.isin(x.L1)]).reset_index(drop=True)

   id L1 L2
0   1  A  C
1   1  A  D
2   1  B  C
3   1  B  D
4   2  D  A
5   2  D  F
相关问题