w3resource

Python Scikit learn: Get observations of each species from iris data

Python Machine learning Iris Basic: Exercise-6 with Solution

Write a Python program to get observations of each species (setosa, versicolor, virginica) from iris data.

Sample Solution:

Python Code:

import pandas as pd
data = pd.read_csv("iris.csv")
print("Observations of each species:")
print(data['Species'].value_counts()) 

Output:

Observations of each species:
Iris-versicolor    50
Iris-virginica     50
Iris-setosa        50
Name: Species, dtype: int64

Python Code Editor:


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to get observations of each species (setosa, versicolor, virginica) from iris data.
Next: Write a Python program to drop Id column from a given Dataframe and print the modified part. Call iris.csv to create the Dataframe.

What is the difficulty level of this exercise?