Fall, 2020
Due: Nov 17 by 11:55 pm (London ON time)
Consider the following Python dictionary data and Python list labels:
= {'animal': ['cat', 'cat', 'snake', 'dog', 'dog', 'cat', 'snake', 'cat', 'dog', 'dog'],
data 'age': [2.5, 3, 0.5, np.nan, 5, 2, 4.5, np.nan, 7, 3],
'visits': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'priority': ['yes', 'yes', 'no', 'yes', 'no', 'no', 'no', 'yes', 'no', 'no']}
= ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] labels
Create a DataFrame df
from this dictionary data
which has the index labels
.
Show the first 3 rows of the DataFrame df
Select just the animal
and age
columns from the DataFrame df
.
Select the rows where the animal is a cat and the age is less than 3.
Calculate the sum of all visits in df (i.e. the total number of visits).
Calculate the mean age for each different animal in df.