Lesson 3 exercises

Data set download


Exercise 3.1

The Anderson-Fisher iris data set is a classic data set used in statistical and machine learning applications. Edgar Anderson carefully measured the lengths and widths of the petals and sepals of 50 irises in each of three species, I. setosa, I. versicolor, and I. virginica. Ronald Fisher then used this data set to distinguish the three species from each other.

a) Load the data set, which you can download here into a Pandas DataFrame called df. Be sure to check out the structure of the data set before loading. You will need to use the header=[0,1] kwarg of pd.read_csv() to load the data set in properly.

b) Take a look df. Is it tidy? Why or why not?

c) Perform the following operations to make a new DataFrame from the original one you loaded in exercise 1 to generate a new DataFrame. You do not need to worry about what these operations do (that is the topic of next week, just do them to answer this question: Is the resulting data frame df_tidy tidy? Why or why not?

[4]:
df_tidy = df.stack(
    level=0
).sort_index(
    level=1
).reset_index(
    level=1
).rename(
    columns={'level_1': 'species'}
)

d) Using df_tidy, slice out all of the sepal lengths for I. versicolor.

Exercise 3.2

a) Make a scatter plot of sepal width versus petal length with the glyphs colored by species.

b) Make a plot comparing the petal widths of the respective species. Comment on why you chose the plot you chose.

Exercise 3.3

Write down any questions or points of confusion that you have.