In [1]: # Initialize OK
from client.api.notebook import Notebook
ok = Notebook('lab04.ok')
Lab 4: Functions and Visualizations
Welcome to Lab 4! This week, we'll learn about functions, table methods such as apply , a
...
In [1]: # Initialize OK
from client.api.notebook import Notebook
ok = Notebook('lab04.ok')
Lab 4: Functions and Visualizations
Welcome to Lab 4! This week, we'll learn about functions, table methods such as apply , and how
to generate visualizations!
Recommended Reading:
Applying a Function to a Column (https://www.inferentialthinking.com/chapters/08/1/applying-afunction-to-a-column.html)
Visualizations (https://www.inferentialthinking.com/chapters/07/visualization.html)
First, set up the notebook by running the cell below.
=====================================================================
Assignment: Functions and Visualizations
OK, version v1.12.5
=====================================================================
In [2]: import numpy as np
from datascience import *
# These lines set up graphing capabilities.
import matplotlib
%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
import warnings
warnings.simplefilter('ignore', FutureWarning)
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
# When you log-in please hit return (not shift + return) after typing
in your email
from client.api.notebook import Notebook
ok = Notebook('lab04.ok')
_ = ok.submit()
Deadline: If you are not attending the lab section, you have to complete this lab and submit by
Wednesday, July 1st before 11:59 P.M. in order to receive lab credit. Otherwise, please attend the
lab you are enrolled in, get checked off with your (u)GSI or tutor AND submit this assignment by
the end of the lab section (with whatever progress you've made) to receive lab credit.
Submission: Once you're finished, select "Save and Checkpoint" in the File menu and then
execute the submit cell at the end. The result will contain a link that you can use to check that your
assignment has been submitted successfully.
=====================================================================
Assignment: Functions and Visualizations
OK, version v1.12.5
=====================================================================
Saving notebook... Saved 'lab04.ipynb'.
Submit... 100% complete
Submission successful for user:
[email protected]
URL: https://okpy.org/cal/data8/su20/lab04/submissions/7pWBJy
1. Defining functions
Let's write a very simple function that converts a proportion to a percentage by multiplying it by
100. For example, the value of to_percentage(.5) should be the number 50 (no percent sign).
A function definition has a few parts.
def
It always starts with def (short for define):
def
Name
Next comes the name of the function. Like other names we've defined, it can't start with a number
or contain spaces. Let's call our function to_percentage :
def to_percentage
Signature
Next comes something called the signature of th
[Show More]