-2

The column("TYPE) contains "IL", "FC", "DT", "MB".

test_data = test_data.drop(test_data[test_data.Type !='IL', 'FC'])

Red
  • 26,798
  • 7
  • 36
  • 58
  • Does this answer your question? [How to filter Pandas dataframe using 'in' and 'not in' like in SQL](https://stackoverflow.com/questions/19960077/how-to-filter-pandas-dataframe-using-in-and-not-in-like-in-sql) – ScootCork Jul 22 '20 at 15:07

1 Answers1

0

Let's say that your dataframe has the index column and the TYPE column only

data = {'TYPE':['IL', 'FC', 'DT', 'MB']}
df = pd.DataFrame(data)
df
  TYPE
0   IL
1   FC
2   DT
3   MB

If you want to delete DT, MB rows (2,3) then you can choose one of the following (not the only ones) :

  1. Define a new dataframe with the two first rows of df only.
df1 = df[:2]
df1
  TYPE
0   IL
1   FC
  1. By droping the values based on their index. Add inplace=True in order to be permanent.
df.drop(df.index[[2,3]], inplace = True)
  1. Return only the desired rows. You can assign it to a new dataframe. This is the closer one to what you were trying I think.
df2 = df[(df['TYPE']!='DT') & (df['TYPE']!='MB')]
df2    
  TYPE
0   IL
1   FC