0

I am using the Iris flower data set:

Enter image description here

In the species, I have three different items of information:

 print(df['Species'].unique())
['setosa' 'versicolor' 'virginica']

I want to filter out all rows and all rows where Species= 'setosa' and Petal.width'= 0.4:

df[df['Species']!='setosa' & (df['Petal.width'] != '0.4')]

The problem is that this function delete all rows which contain df['Species']=='setosa' and all rows which contains df['Petal.width'] == '0.4'.

I want to apply two conditions in the same time.

How do I solve the problem?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
dina
  • 351
  • 1
  • 3
  • 9
  • Use `df[(df['Species']!='setosa') & (df['Petal.width'] != 0.4)]` – jezrael Mar 21 '19 at 08:12
  • I think you need use `df[(df['Species'] == 'setosa') & (df['Petal.width'] == 0.4)]` – Space Impact Mar 21 '19 at 08:15
  • @jezrael Thank you but that is what I have already did. It does not work; It delete all lines df['Species']!='setosa'. That is not my goal. I want to delete rows where I have both df['Species']!='setosa') & (df['Petal.width'] != 0.4). I want to apply both conditions in the same time. – dina Mar 21 '19 at 08:17
  • @dina - Yes, I understand. Solution in first comemnt not working? – jezrael Mar 21 '19 at 08:39
  • @jezrael thank you for your answer but it does not work. – dina Mar 21 '19 at 08:44
  • `df[(df['Species']!='setosa') & (df['Petal.width'] != '0.4')]` working ? – jezrael Mar 21 '19 at 08:47

0 Answers0