我尝试过
df.groupby(['Machine','SLOTID'])['COMPONENT_ID'].unique()
输出如下:
Machine COMPONENT_ID
LM5 11S02CY382YH1934472901 [N3CP1.CP]
11S02CY382YH1934620648 [N4CP0.CP]
11S02CY388YH1934546857 [N2CP0.CP]
11S02CY388YH1934590637 [N0CP0.CP]
11S02CY388YH1934591337 [N4CP0.CP]
...
M05 11S02CY395YH1934575728 [N5CP1.CP]
11S02CY395YH1934658824 [N3CP1.CP]
11S02CY395YH1934662750 [N1CP1.CP]
11S02CY395YH1934703310 [N5CP1.CP]
11S02CY395YH1934801982 [N5CP1.CP]
Name: SLOTID, Length: 388, dtype: object
如您所见,SLOTID在表中只有一个值,但是表足够长,我想知道(Machine,COMPONENT_ID)的任何组是否具有多个SLOTID值。
答案 0 :(得分:1)
您可以只对所需的列进行分组,并在任意条件下对目标列进行转换。用它来切片原始DF将返回您想要的。
df[df.groupby(['Machine','COMPONENT_ID'])['SLOTID'].transform('nunique')>1]