how to add a column in a data frame based on operations on values in multiple rows of another data frame?
So this is my initial data frame example.
and I want output as below
where
Example
till now I tried to add a new data frame using unique(ord_date,crt_code and del_date combination) and then tried to compute the score for each line but I'm not getting how to put an if the condition.
df2['score'][(df2['ord_date']==xxxx)&(df2['crt_code']==xxxx)&(df2['del_date']==xxxx)]
= if(df['val1'][(df['slb_qty']==2)&(df['ord_date']==xxxx)&(df['crt_code']==xxxx)&(df['del_date']==xxxx)] + df['val1'][(df['slb_qty']==12)&(df['ord_date']==xxxx)&(df['crt_code']==xxxx)&(df['del_date']==xxxx)] >=80 ) then 200
plus this will become a very large statement to check all 4 conditions which will be hard to read.
Can anyone suggest how to achieve my desired output if possible in a cleaner/simple way?



