I've looked but seem to be coming up dry for an answer to the following question.
I have a pandas dataframe analogous to this (call it 'df'):
Type Set
1 theGreen Z
2 andGreen Z
3 yellowRed X
4 roadRed Y
I want to add another column to the dataframe (or generate a series) of the same length as the dataframe (= equal number of records/rows) which assigns a numerical coding variable (1) if the Type contains the string "Green", (0) otherwise.
Essentially, I'm trying to find a way of doing this:
df['color'] = np.where(df['Type'] == 'Green', 1, 0)
Except instead of the usual numpy operators (<,>,==,!=, etc.) I need a way of saying "in" or "contains". Is this possible? Any and all help appreciated!