Why is np.where not returning '1'? Only returns '0'
You are first checking if the item contains the string, but then in np.where you are checking if the values are equal (item == s), which is obviously different. In addition, you set the whole column equal to the value from np.where (and overwriting it after each row), which results in the whole column getting the value based on the final row of the dataframe.
To avoid looping over the rows (which is relatively quite slow) you can use pandas.Series.str.contains to check if a string contains a certain value like this:
df[&quot;orc_4&quot;] = np.where(df[&quot;indictment_charges&quot;].str.contains(&quot;2907.04&quot;), 1, 0)