Tuesday, February 13, 2018

Learning Pandas and Plotly in Jupyter Notebooks

I'm very excited about the Callyso Project, so I've been playing around with Pandas and some data visualization tools (Plotly and Bokeh) in Jupyter notebooks. I'm more familiar with Plotly, so I started with that.

import pandas as pd
import plotly
from plotly.graph_objs import Scatter, Layout
plotly.offline.init_notebook_mode(connected=True)
plo = plotly.offline.iplot
results = pd.read_excel('https://education.alberta.ca/media/3680582/diploma-multiyear-auth-list-annual.xlsx')
years = []
for value in results.columns.values:
try: # check if first four digits are a number (a year)
year = value[0:4]
int(year)
if year not in years:
years.append(year)
except (TypeError, ValueError):
pass
schoolAuthority = 'Elk Island Public Schools Regional Division No. 14'
interestingRows = []
for row in results.iterrows():
if row[1]['Authority Name'] == schoolAuthority:
rowNumber = row[0]
interestingRows.append(rowNumber)
lookingFor = 'Auth School Mark % Exc'
x = years
y = []
for rowNumber in interestingRows:
for year in years:
findThis = year + ' ' + lookingFor
y.append(results.iloc[rowNumber][findThis])
plo({
"data": [Scatter(x=x, y=y)],
"layout": Layout(
yaxis=dict(range=[0,100]),
title=results.iloc[rowNumber]['Diploma Course'] + '<br>' + lookingFor + '<br>' + schoolAuthority
)
})
y = []

1 comment:

Joe Mann said...

Love what you're doing with Jupyter notebooks in the schools! (or Jupyterlab..?)

I did want to suggest that you check out altair https://altair-viz.github.io/ as a plotting library.
(If you haven't already)
Very clean interface with options for interactive graphics.



good luck with this!
Joe