我在数据框中分组了4个变量。
with pd.option_context('display.max_rows', None, 'display.max_columns', None):
print(df_test[df_test['SLOTID'].isin(['N0CP0.CP','N2CP0.CP','N4CP0.CP','N6CP0.CP' ])][['SLOTID','LANE','Loss','EYE_WIDTH']].groupby(['SLOTID','LANE','Loss','EYE_WIDTH']).agg(list))
SLOTID LANE Loss EYE_WIDTH
N0CP0.CP 0 10.381169 62.4 [SLOTID, LANE, Loss, EYE_WIDTH]
10.404240 50.7 [SLOTID, LANE, Loss, EYE_WIDTH]
54.6 [SLOTID, LANE, Loss, EYE_WIDTH]
58.5 [SLOTID, LANE, Loss, EYE_WIDTH]
62.4 [SLOTID, LANE, Loss, EYE_WIDTH]
66.3 [SLOTID, LANE, Loss, EYE_WIDTH]
70.2 [SLOTID, LANE, Loss, EYE_WIDTH]
1 10.150914 62.4 [SLOTID, LANE, Loss, EYE_WIDTH]
10.196356 54.6 [SLOTID, LANE, Loss, EYE_WIDTH]
58.5 [SLOTID, LANE, Loss, EYE_WIDTH]
62.4 [SLOTID, LANE, Loss, EYE_WIDTH]
66.3 [SLOTID, LANE, Loss, EYE_WIDTH]
70.2 [SLOTID, LANE, Loss, EYE_WIDTH]
2 9.946152 50.7 [SLOTID, LANE, Loss, EYE_WIDTH]
54.6 [SLOTID, LANE, Loss, EYE_WIDTH]
58.5 [SLOTID, LANE, Loss, EYE_WIDTH]
现在,我的要求是在数据框中(最好在该Loss变量旁边)打印每个“丢失”值的出现次数。