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

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?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/machine-learning/scikit-learn/iris/python-machine-learning-scikit-learn-iris-basic-exercise-6.php