-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassessment.py
More file actions
107 lines (67 loc) · 4.83 KB
/
assessment.py
File metadata and controls
107 lines (67 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# -*- coding: utf-8 -*-
"""Assessment.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/github/byui-cse/cse450-course/blob/master/notebooks/module01-assessment.ipynb
# Introduction
This assignment will test how well you're able to perform various data science-related tasks.
Each Problem Group below will center around a particular dataset that you have worked with before.
To ensure you receive full credit for a question, make sure you demonstrate the appropriate pandas, altair, or other commands as requested in the provided code blocks.
You may find that some questions require multiple steps to fully answer. Others require some mental arithmetic in addition to pandas commands. Use your best judgment.
## Submission
Each problem group asks a series of questions. This assignment consists of two submissions:
1. After completing the questions below, open the Module 01 Assessment Quiz in Canvas and enter your answers to these questions there.
2. After completing and submitting the quiz, save this Colab notebook as a GitHub Gist (You'll need to create a GitHub account for this), by selecting `Save a copy as a GitHub Gist` from the `File` menu above.
In Canvas, open the Module 01 Assessment GitHub Gist assignment and paste the GitHub Gist URL for this notebook. Then submit that assignment.
## Problem Group 1
For the questions in this group, you'll work with the Netflix Movies Dataset found at this url: [https://raw.githubusercontent.com/byui-cse/cse450-course/master/data/netflix_titles.csv](https://raw.githubusercontent.com/byui-cse/cse450-course/master/data/netflix_titles.csv)
### Question 1
Load the dataset into a Pandas data frame and determine what data type is used to store the `release_year` feature.
"""
import pandas as pd
netflix = pd.read_csv("https://raw.githubusercontent.com/byui-cse/cse450-course/master/data/netflix_titles.csv")
print(netflix.dtypes["release_year"])
"""### Question 2
Filter your dataset so it contains only `TV Shows`. How many of those TV Shows were rated `TV-Y7`?
"""
tv_shows = netflix[netflix["type"] == "TV Show"]
count_tv_y7 = tv_shows[tv_shows["rating"] == "TV-Y7"].shape[0]
print(count_tv_y7)
"""### Question 3
Further filter your dataset so it only contains TV Shows released between the years 2000 and 2009 inclusive. How many of *those* shows were rated `TV-Y7`?
"""
tv_2000s = tv_shows[(tv_shows["release_year"] >= 2000) & (tv_shows["release_year"] <= 2009)]
count_tv_y7_2000s = tv_2000s[tv_2000s["rating"] == "TV-Y7"].shape[0]
print(count_tv_y7_2000s)
"""## Problem Group 2
For the questions in this group, you'll work with the Cereal Dataset found at this url: [https://raw.githubusercontent.com/byui-cse/cse450-course/master/data/cereal.csv](https://raw.githubusercontent.com/byui-cse/cse450-course/master/data/cereal.csv)
### Question 4
After importing the dataset into a pandas data frame, determine the median amount of `protein` in cereal brands manufactured by Kelloggs. (`mfr` code "K")
"""
cereal = pd.read_csv("https://raw.githubusercontent.com/byui-cse/cse450-course/master/data/cereal.csv")
kelloggs = cereal[cereal["mfr"] == "K"]
median_protein = kelloggs["protein"].median()
print(median_protein)
"""### Question 5
In order to comply with new government regulations, all cereals must now come with a "Healthiness" rating. This rating is calculated based on this formula:
healthiness = (protein + fiber) / sugar
Create a new `healthiness` column populated with values based on the above formula.
Then, determine the median healthiness value for only General Mills cereals (`mfr` = "G"), rounded to two decimal places.
"""
cereal["healthiness"] = (cereal["protein"] + cereal["fiber"]) / cereal["sugars"]
general_mills = cereal[cereal["mfr"] == "G"]
median_healthiness = round(general_mills["healthiness"].median(), 2)
print(median_healthiness)
"""## Problem Group 3
For the questions in this group, you'll work with the Titanic Dataset found at this url: [https://raw.githubusercontent.com/byui-cse/cse450-course/master/data/titanic.csv](https://raw.githubusercontent.com/byui-cse/cse450-course/master/data/titanic.csv)
### Question 6
After loading the dataset into a pandas DataFrame, create a new column called `NameGroup` that contains the first letter of the passenger's surname in lower case.
Note that in the dataset, passenger's names are provided in the `Name` column and are listed as:
Surname, Given names
For example, if a passenger's `Name` is `Braund, Mr. Owen Harris`, the `NameGroup` column should contain the value `b`.
Then count how many passengers have a `NameGroup` value of `k`.
"""
titanic = pd.read_csv("https://raw.githubusercontent.com/byui-cse/cse450-course/master/data/titanic.csv")
titanic["NameGroup"] = titanic["Name"].str.split(",").str[0].str[0].str.lower()
count_k = titanic[titanic["NameGroup"] == "k"].shape[0]
print(count_k)