10. Exploring the Iris Data Set#
How to do it#
Import the
plotly.express
module aspx
import plotly.express as px
Load the data set and check its type
iris = px.data.iris()
type(iris)
pandas.core.frame.DataFrame
Inspect the
DataFrame
using the methodhead
andtail
iris.head()
sepal_length | sepal_width | petal_length | petal_width | species | species_id | |
---|---|---|---|---|---|---|
0 | 5.1 | 3.5 | 1.4 | 0.2 | setosa | 1 |
1 | 4.9 | 3.0 | 1.4 | 0.2 | setosa | 1 |
2 | 4.7 | 3.2 | 1.3 | 0.2 | setosa | 1 |
3 | 4.6 | 3.1 | 1.5 | 0.2 | setosa | 1 |
4 | 5.0 | 3.6 | 1.4 | 0.2 | setosa | 1 |
iris.tail()
sepal_length | sepal_width | petal_length | petal_width | species | species_id | |
---|---|---|---|---|---|---|
145 | 6.7 | 3.0 | 5.2 | 2.3 | virginica | 3 |
146 | 6.3 | 2.5 | 5.0 | 1.9 | virginica | 3 |
147 | 6.5 | 3.0 | 5.2 | 2.0 | virginica | 3 |
148 | 6.2 | 3.4 | 5.4 | 2.3 | virginica | 3 |
149 | 5.9 | 3.0 | 5.1 | 1.8 | virginica | 3 |
Use the method
describe
iris.describe()
sepal_length | sepal_width | petal_length | petal_width | species_id | |
---|---|---|---|---|---|
count | 150.000000 | 150.000000 | 150.000000 | 150.000000 | 150.000000 |
mean | 5.843333 | 3.054000 | 3.758667 | 1.198667 | 2.000000 |
std | 0.828066 | 0.433594 | 1.764420 | 0.763161 | 0.819232 |
min | 4.300000 | 2.000000 | 1.000000 | 0.100000 | 1.000000 |
25% | 5.100000 | 2.800000 | 1.600000 | 0.300000 | 1.000000 |
50% | 5.800000 | 3.000000 | 4.350000 | 1.300000 | 2.000000 |
75% | 6.400000 | 3.300000 | 5.100000 | 1.800000 | 3.000000 |
max | 7.900000 | 4.400000 | 6.900000 | 2.500000 | 3.000000 |
Make a scatter plot to visualize the relationship between petal lenght and petal width
fig = px.scatter(iris, x='petal_length', y ='petal_width')
fig.show()
Enhance the scatter plot by adding color the dots according to the species
fig = px.scatter(iris, x='petal_length', y='petal_width', color='species')
fig.show()
Make a similar scatter plot to visualize the relationship between sepal lenght and sepal width by species
fig = px.scatter(iris, x='sepal_length', y='sepal_width', color='species')
fig.show()