I have a dataframe
df = pd.DataFrame([["A","X",1], ["B","W",0.9], ["B","X",0.8],
["A","W",0.7], ["B","Z",8], ["B","Y",48],
["A","Y",98],["A","Z",56]], columns=["id","key","val"])
After groupby on id column, in column key, among W and X whichever appears first retain that row and drop the other, similarly among Y and Z retain the row based on whichever appears first and drop the other after groupby/common id.
Expected output:
df_out = pd.DataFrame([["A","X",1], ["B","W",0.9], ["B","Z",8],
["A","Y",98]], columns=["id","key","val"])
How to do it?