I'm trying to run this piece of code:
df['ID'] =df.groupby(["Code","Number"]).apply(lambda x: x['O'].isin(x['D']) | x['D'].isin(x['O']) & (x['O'] != x['D'])).values
with the following input:
data1 ={"Code":["A","A","A"], "Number":[7,7,7],"O":["BR","AC","BR"],"D":["AC","LF","LF"]}
df=pd.DataFrame(data1)
I get the following error, if I have only one group (on Code & Number) in the input data frame:
data = array([[ True, True, False]])
index = Int64Index([0, 1, 2], dtype='int64')
ValueError: Length of values (1) does not match length of index (3)
If I use another input with multiple rows and groups, I don't get any errors. I don't really understand what's the problem and how can I fix it.