Question: Consider the following Python dictionary data and Python list labels: data = { ' animal ' : [ ' cat ' , 'cat', 'snake', 'dog',

Consider the following Python dictionary data and Python list labels:
data ={'animal': ['cat', 'cat', 'snake', 'dog', 'dog', 'cat', 'snake', 'cat', 'dog', 'dog'],
'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']}
labels =['a','b','c','d','e','f','g','h','i','j']
Calculate the mean age for each different animal in df.
Append a new row 'k' to df with your choice of values for each column. Then delete that row to return the original DataFrame.
Count the number of each type of animal in df.
Sort df first by the values in the 'age' in decending order, then by the value in the 'visits' column in ascending order (so row i should be first, and row d should be last).
For each animal type and each number of visits, find the mean age. In other words, each row is an animal, each column is a number of visits and the values are the mean ages (hint: use a pivot table).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!