i have 2 set of data and i would like to find and match by condition and i do not want my matched result to be repeated if have similar criteria.
data as below:
df = pd.DataFrame({'date' : ['16-04-2020', '20-04-2020', '16-04-2020', '16-04-2020', '20-04-2020', '20-04-2020', '16-04-2020'],
'item' : ['X-317', 'ry-186', 'opq-468','999-xq','789-44','154-abc','opq-468'],
'no': ['36','55','45','77','107','1149','456' ],
'result':['','','','','','','']})
df_list = pd.DataFrame({'date' : ['16-04-2020', '16-04-2020', '16-04-2020', '20-04-2020', '16-04-2020', '16-04-2020', '20-04-2020'],
'item' : ['X-317', 'ry-186','789-44','154-abc', 'opq-468','opq-468','123-x'],
'complete': ['yes','no','on-going','yes','yes','yes','no' ],
'code':['alpha', 'vertical','horizon','grand','empire','jade','roms']})
my intention is to match date, complete = 'yes' and item in df is same as df_list, but if there is similar from the result, it will proceed to find next one
i tried below but it keep shows me 2 similar result, and if i add a break, it will not shows the result
listrange = []
for i in range(len(df_list)):
for j in range(len(df)):
if ((df_list['date'][i] == df['date'][j] ) and (df_list['complete'][i] == 'yes') and (df_list['item'][i] == df['item'][j])):
df['result'][j] = df_list['code'][i]
# break
print(df)
OUTPUT(1):
date item no result
0 16-04-2020 X-317 36 alpha
1 20-04-2020 ry-186 55
2 16-04-2020 opq-468 45 jade
3 16-04-2020 999-xq 77
4 20-04-2020 789-44 107
5 20-04-2020 154-abc 1149 grand
6 16-04-2020 opq-468 456 jade
OUTPUT(1): >>>>>>>>>>>>>>>>>>>>>> with break in the code
date item no result
0 16-04-2020 X-317 36 alpha
1 20-04-2020 ry-186 55
2 16-04-2020 opq-468 45 jade
3 16-04-2020 999-xq 77
4 20-04-2020 789-44 107
5 20-04-2020 154-abc 1149 grand
6 16-04-2020 opq-468 456
EXPECTED result should be as below:
date item no result
0 16-04-2020 X-317 36 alpha
1 20-04-2020 ry-186 55
2 16-04-2020 opq-468 45 empire
3 16-04-2020 999-xq 77
4 20-04-2020 789-44 107
5 20-04-2020 154-abc 1149 grand
6 16-04-2020 opq-468 456 jade