This is a Jupyter notebook. We'll write all of our code in this class in a Jupyter notebook.
Today, don't worry about how any of this works. Throughout the semester, we'll learn how each of these pieces work.
Note: The maps in this notebook will not load correctly in Safari if you're on a Mac; use Chrome.
!pip install googlemaps
from datascience import *
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import plotly.graph_objects as go
import googlemaps
# "KEY" is sensitive (it's almost like a password).
# I've removed mine in this posted version of the notebook, so some of the code won't run for you.
KEY = 'xxx'
Here, we'll load in data about all public universities in California. The data comes from this Wikipedia article.
uni = Table.read_table('data/california_universities.csv')
uni = uni.with_columns(
'Enrollment', uni.apply(lambda s: int(s.replace(',', '')), 'Enrollment'),
'Founded', uni.apply(lambda s: int(s.replace('*', '')), 'Founded')
)
Data is often stored in tables. In about a month, we'll become very, very familiar with how tables work. But for now, let's just observe.
uni.show(15)
Let's start asking questions.
uni.sort('Enrollment', descending = True)
uni.sort('Enrollment', descending = True).barh('Name', 'Enrollment')
uni.sort('Founded')
uni_copy = uni.sort('Founded').with_columns('Total Universities', np.arange(1, uni.num_rows + 1))
uni_copy.plot('Founded', 'Total Universities')
Let's add some spice.
fig = go.Figure()
fig.add_trace(
go.Scatter(x = uni_copy.column('Founded'),
y = uni_copy.column('Total Universities'),
hovertext = uni_copy.column('Name'),
mode = 'markers',
)
)
fig.add_trace(
go.Scatter(x = uni_copy.column('Founded'),
y = uni_copy.column('Total Universities'),
line = dict(color = 'blue'),
)
)
fig.update_layout(title = 'Total Number of Public Universities in California by Year',
xaxis_title = 'Year',
yaxis_title = 'Total Universities')
fig.show()