I have a dataframe column like this:
df['col_name'].unique()
>>>array([-1, 'Not Passed, On the boundary', 1, 'Passed, On the boundary',
'Passed, Unclear result', 'Passes, Unclear result, On the boudnary',
'Rejected, Unclear result'], dtype=object)
In this column,
if an element contains the word ‘Passed’ as a field or as a substring, then replace the entire field with integer 1 else replace it with integer -1.
Kindly help me with this
>Solution :
You can use np.where
df['col_name'] = np.where(df['col_name'].str.contains('Passed'), 1, -1)