Sample DF:
ID Name Match1 Random_Col Match2 Price Match3 Match4 Match5
1 Apple Yes Random Value No 10 Yes Yes Yes
2 Apple Yes Random Value1 No 10 Yes Yes No
3 Apple Yes Random Value2 No 15 No Yes Yes
4 Orange No Random Value Yes 12 Yes Yes No
5 Orange No Random Value Yes 12 No No No
6 Banana Yes Random Value No 15 Yes No No
7 Apple Yes Random Value No 15 No Yes Yes
Expected DF:
ID Name Match1 Random_Col Match2 Price Match3 Match4 Match5 Final_Match
1 Apple Yes Random Value No 10 Yes Yes Yes Full
2 Apple Yes Random Value1 No 10 Yes Yes No Partial
3 Apple Yes Random Value2 No 15 No Yes Yes Partial
4 Orange No Random Value Yes 12 Yes Yes No Full
5 Orange No Random Value Yes 12 No No No Partial
6 Banana Yes Random Value No 15 Yes No No Full
7 Apple Yes Random Value No 15 No Yes Yes Partial
Problem Statement:
- If combination
NameandPriceis non-repetitive simply putFullinFinal_Matchcolumn (Example ID 6) If the combination
NameandPriceare repetitive then within them countYesin Match1 to Match5 columns, whichever has greater "Yes" putFullfor that one andPartialfor the other (Example ID 1 & 2 and 4,5)If the combination
NameandPriceare repetitive then within an ID countYesin Match1 to Match5 columns,if they have equal "Yes" putPartialin both (Example ID 3,7)
Code
s = (df.replace({'Yes': 1, 'No': 0})
.iloc[:, 1:]
.sum(1))
df['final_match'] = np.where(s.groupby(df[['Price','Name']]).rank(ascending=False).eq(1), 'Full ','Partial')
The above code works when I had to groupby by only 1 column lets say Name but it is not working for combination.
Any help!!