Here is my data frame:
import pandas as pd
data = {'Period':['Group 1 vs Group 2:Change at 3 mo', 'Group 1:Change at 3 mo', 'Group 1 vs Group 2:Change at 3 mo', 'Group 2:Change at 3 mo'], 'estimate':[20, 21, 19, 18]}
df = pd.DataFrame(data)
Now I need to get only rows that in variable Period do not contain anywhere Group 1 vs Group 2. I tried this code:
df = df.loc[df['Period'].str.contains(pat = '(?!Group 1 vs Group 2)', regex = True)].reset_index(drop=True)
But it does not filters rows and I am getting original df as a result. How to fix my code so I will get only rows that in variable Period do not contain anywhere Group 1 vs Group 2?
df[~df['Period'].str.contains(r'Group 1 vs Group 2')]