0

I am trying to currently using the Iris classification dataset with Python and Pandas to do some data analysis. I'm trying to print all the petal-length values that are greater than 1.7 and where the data species is Setosa but I'm having a problem.

I keep getting this error:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Here is my code:

iris = pd.read_csv(r"C:\Users\username\Downloads\iris.csv")
for row in iris:
    if iris["species"] == "setosa":
         if iris["petal_width"] > 1.7:
            print(iris["petal_width"])

Any help or suggestions you can give me I would greatly appreciate it. Thank you!

Qi'ra
  • 37
  • 6
  • `print(iris.loc[(iris["species"] == "setosa") & (iris["petal_width"] > 1.7),"petal_width"])`? – Anurag Dabas May 10 '21 at 03:19
  • Does this answer your question? [Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()](https://stackoverflow.com/questions/36921951/truth-value-of-a-series-is-ambiguous-use-a-empty-a-bool-a-item-a-any-o) – paradocslover May 10 '21 at 03:43

2 Answers2

1
print(iris.query("petal_length>1.7 & species=='setosa'")['petal_length'])
James Brooke
  • 91
  • 1
  • 3
-1

From Anurag's comment

print(iris.loc[(iris["species"] == "setosa") & (iris["petal_width"] > 1.7),"petal_width"])
Shubham Periwal
  • 2,198
  • 2
  • 8
  • 26