I have a dataframe, want to create third column say col3 based on the condition if col2 value is present in col1 then 'Yes' else 'No'
data = [[[('330420', 0.9322496056556702), ('76546', 0.9322003126144409)],76546],[[('330420', 0.9322496056556702), ('500826', 0.9322003126144409)],876546]]
test = pd.DataFrame(data, columns=['col1','col2'])
col1 col2
0 [(330420, 0.9322496056556702), (76546, 0.93220... 76546
1 [(330420, 0.9322496056556702), (500826, 0.9322... 876546
Desired result:
data = [[[('330420', 0.9322496056556702), ('76546', 0.9322003126
144409)],76546, 'Yes'],[[('330420', 0.9322496056556702), ('500826', 0.9322003126144409)],876546,'No']]
test = pd.DataFrame(data, columns=['col1','col2', 'col3'])
col1 col2 col3
0 [(330420, 0.9322496056556702), (76546, 0.93220... 76546 Yes
1 [(330420, 0.9322496056556702), (500826, 0.9322... 876546 No
My Solution:
test['col3'] = [entry for tag in test['col2'] for entry in test['col1'] if tag in entry]
Getting error: ValueError: Length of values does not match length of index