I am using pandas to filter a data frame using str.contains() but my logic is dropping values that I might want to keep given the string. I don't know how to use Pandas to sort this out.
A sample cell in the excel sheet that I am working with would look like:
Case #1: Don't flag this because there is a different recipient, bob@gmail.com
Recipient
---------
joe@work.com, bob@gmail.com, sally@work.com
Case #2: Flag this because every recipient contains @work.com
Recipient
---------
mike@work.com, taylor@work.com, barbra@work.com
I have a situation where I only need it to filter if a specific value occurs. For example, if 'Recipient' contains the email joe@work.com, drop this value. But if Recipient column contains 'joe@work.com, bob@gmail.com' (Yes, the values are separated in a comma like that in a single cell.) and keep it. Eventually, this dataframe will be dropped from a final report. So I want to drop everything that just contains @work.com, but don't drop if it contains a @gmail.com, @work.com.
This query below is dropping everything even if the Recipient column contains 'gmail.com'
df['EMAIL10'] = df['Type'].str.contains('Email') & df['Type'].str.contains(
'Tracking | Data') & df[
'Recipient'].str.contains('@work.com')
Let me know if I need to clarify