from datascience import *
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plots
plots.style.use('fivethirtyeight')
cars = Table.read_table('hybrid.csv')
cars = cars.where('class', are.contained_in("Compact SUV Minivan"))
cars
vehicle | year | msrp | acceleration | mpg | class |
---|---|---|---|---|---|
Prius (1st Gen) | 1997 | 24509.7 | 7.46 | 41.26 | Compact |
Tino | 2000 | 35355 | 8.2 | 54.1 | Compact |
Prius (2nd Gen) | 2000 | 26832.2 | 7.97 | 45.23 | Compact |
Civic (1st Gen) | 2001 | 25833.4 | 7.04 | 47.04 | Compact |
Alphard | 2003 | 38084.8 | 8.33 | 40.46 | Minivan |
Civic | 2003 | 14071.9 | 8.62 | 41 | Compact |
Escape | 2004 | 36676.1 | 10.32 | 31.99 | SUV |
Lexus RX400h | 2005 | 58521.1 | 12.76 | 28.23 | SUV |
Civic (2nd Gen) | 2005 | 26354.4 | 7.63 | 39.99 | Compact |
Highlander | 2005 | 29186.2 | 12.76 | 29.4 | SUV |
... (65 rows omitted)
from IPython.display import HTML
from IPython.display import display
# Taken from https://stackoverflow.com/questions/31517194/how-to-hide-one-specific-cell-input-or-output-in-ipython-notebook
tag = HTML('''<script>
code_show=true;
function code_toggle() {
if (code_show){
$('div.cell.code_cell.rendered.selected div.input').hide();
} else {
$('div.cell.code_cell.rendered.selected div.input').show();
}
code_show = !code_show
}
$( document ).ready(code_toggle);
</script>
To show/hide this cell's raw code input, click <a href="javascript:code_toggle()">here</a>.''')
display(tag)
############### Write code below ##################
cars.scatter('msrp','mpg')
from IPython.display import HTML
from IPython.display import display
# Taken from https://stackoverflow.com/questions/31517194/how-to-hide-one-specific-cell-input-or-output-in-ipython-notebook
tag = HTML('''<script>
code_show=false;
function code_toggle() {
if (code_show){
$('div.cell.code_cell.rendered.selected div.input').hide();
} else {
$('div.cell.code_cell.rendered.selected div.input').show();
}
code_show = !code_show
}
$( document ).ready(code_toggle);
</script>
To show/hide this cell's raw code input, click <a href="javascript:code_toggle()">here</a>.''')
display(tag)
############### Write code below ##################
cars.scatter('msrp','mpg')
from IPython.core.display import display, HTML
toggle_code_str = '''
<form action="javascript:code_toggle()"><input type="submit" id="toggleButton" value="Show Sloution"></form>
'''
toggle_code_prepare_str = '''
<script>
function code_toggle() {
if ($('div.cell.code_cell.rendered.selected div.input').css('display')!='none'){
$('div.cell.code_cell.rendered.selected div.input').hide();
} else {
$('div.cell.code_cell.rendered.selected div.input').show();
}
}
</script>
'''
def toggle_code():
display(HTML(toggle_code_str))
cars.scatter('msrp','mpg')
toggle_code()
from IPython.core.display import display, HTML
toggle_code_str = '''
<form action="javascript:code_toggle()"><input type="submit" id="toggleButton" value="Click Here to Hide Code Above
(Too Advanced for Us)"></form>
'''
toggle_code_prepare_str = '''
<script>
function code_toggle() {
if ($('div.cell.code_cell.rendered.selected div.input').css('display')!='none'){
$('div.cell.code_cell.rendered.selected div.input').hide();
} else {
$('div.cell.code_cell.rendered.selected div.input').show();
}
}
</script>
'''
display(HTML(toggle_code_prepare_str + toggle_code_str))
def hide_code():
display(HTML(toggle_code_str))
hide_code()
cars.scatter('msrp','mpg')
plots.title("Hide Code");
Occasionally we'll see something like this in the code:
That means that a bunch of Python code was used to create something, usually a graphic, whose REAL purpose is to demonstrate something statistical or mathematical, AND the code to create it is either more advanced than we're supposed to worry with, or just really long. Either way, just click the button to hide the code, forget about it, then focus on the thing the code is demonstrating.