Issue
I use this code to see if details contain Mercedes and details contains 123
.
How do I do to get details that contain Mercedes and doesn't contains 123
.
color1 = "Mercedes 123"
color2 = "Green not sold"
#----- Applying the condition
df['check'] = df['check'].mask(df['Details'].str.contains('Mercedes') & df['Details'].str.contains('123'), color1)
Solution
Use and
to combine the conditions and not
to negate the second condition:
color1 = "Mercedes 123"
color2 = "Green not sold"
#----- Applying the condition
df['check'] = df['check'].mask(df['Details'].str.contains('Mercedes') and not df['Details'].str.contains('123'), color1)
Answered By - Manos Kounelakis
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.