Skip to content

Instantly share code, notes, and snippets.

@misterhay
Last active February 14, 2018 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misterhay/6f025d7fa5eb92719ae7c2431ab4e6e1 to your computer and use it in GitHub Desktop.
Save misterhay/6f025d7fa5eb92719ae7c2431ab4e6e1 to your computer and use it in GitHub Desktop.
experimenting with Panada and Plotly offline in Jupyter for visualizing open data
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 = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment