I can identify the rows I want to remove from a dataframe using the following code:
df[(df.Year.isin(range(200,205))) & (df.id== 'string')]
How do I remove these rows from the dataframe?
I tried the following solution but it didn't work:
df.drop[(df.Year.isin(range(200,205))) & (df.id== 'string'), axis = 0]
CodePudding user response:
You can drop the rows by index as well
df.drop(df[(df.Year.isin(range(200,205))) & (df.id== 'string')].index, inplace=True)
Another way suggested by @JoshFriedlander
df = df[~((df.Year.isin(range(200,205))) & (df.id== 'string'))]
CodePudding user response:
my go to solution would be:
df = df[(df['year'] >= 200) & (df['year'] <= 205) & (df['id'] == 'string')]