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()) 

Sample Output:

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

Go to:


PREV : 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.

Python Code Editor:


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

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.