This is a Jupyter Notebook in the Julia programming language by Oleg Lavrovsky based on Jupyter Notebooks : a powerful data analysis and wrangling tool (Python resources here) facilitated by Jan Krause (EPFL Library) at DataJamDays 2017.

24.11.2017 | Crative Commons License: CC BY-SA 4.0

Notebooks are for Math!

\begin{equation*} \left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right) \end{equation*}

Notebooks are interactive!

In [1]:
a = 3*2
Out[1]:
6

Notebooks are REALLY interactive!

In [2]:
using Gadfly, Interact
In [3]:
@manipulate for ϕ=0:π/16:4π, f=[:sin => sin, :cos => cos]
    plot(θ -> f(θ + ϕ), 0, 25)
end
Out[3]:
x -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 -25 0 25 50 -26 -24 -22 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 -3.0 -2.9 -2.8 -2.7 -2.6 -2.5 -2.4 -2.3 -2.2 -2.1 -2.0 -1.9 -1.8 -1.7 -1.6 -1.5 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 -4 -2 0 2 4 -3.0 -2.8 -2.6 -2.4 -2.2 -2.0 -1.8 -1.6 -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 f(x)

And of course, we can print stuff too:

In [4]:
print("Hello")
println(" World")
Hello World
In [5]:
lists_are_fun = [1, 2, 3]
for n in lists_are_fun
    print("$n.. ") 
end
1.. 2.. 3.. 

Plot some points and curves:

In [16]:
plot(x=1:10, y=2.^rand(10),
     Scale.y_sqrt, Geom.point, Geom.smooth)
Out[16]:
x -12.5 -10.0 -7.5 -5.0 -2.5 0.0 2.5 5.0 7.5 10.0 12.5 15.0 17.5 20.0 22.5 -10.0 -9.5 -9.0 -8.5 -8.0 -7.5 -7.0 -6.5 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 12.5 13.0 13.5 14.0 14.5 15.0 15.5 16.0 16.5 17.0 17.5 18.0 18.5 19.0 19.5 20.0 -10 0 10 20 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 0.702 0.752 0.802 0.852 0.902 0.952 1.002 1.052 1.102 1.152 1.202 1.252 1.302 1.352 1.402 1.452 1.502 1.552 0.752 0.762 0.772 0.782 0.792 0.802 0.812 0.822 0.832 0.842 0.852 0.862 0.872 0.882 0.892 0.902 0.912 0.922 0.932 0.942 0.952 0.962 0.972 0.982 0.992 1.002 1.012 1.022 1.032 1.042 1.052 1.062 1.072 1.082 1.092 1.102 1.112 1.122 1.132 1.142 1.152 1.162 1.172 1.182 1.192 1.202 1.212 1.222 1.232 1.242 1.252 1.262 1.272 1.282 1.292 1.302 1.312 1.322 1.332 1.342 1.352 1.362 1.372 1.382 1.392 1.402 1.412 1.422 1.432 1.442 1.452 1.462 1.472 1.482 1.492 1.502 0.752 1.002 1.252 1.502 0.742 0.762 0.782 0.802 0.822 0.842 0.862 0.882 0.902 0.922 0.942 0.962 0.982 1.002 1.022 1.042 1.062 1.082 1.102 1.122 1.142 1.162 1.182 1.202 1.222 1.242 1.262 1.282 1.302 1.322 1.342 1.362 1.382 1.402 1.422 1.442 1.462 1.482 1.502 y

Doing math in Julia is more fun!

In [232]:
equation(x) = (x + 2) * (x - 1) * (x - 2) + (4 - x^2)
Out[232]:
equation (generic function with 1 method)
In [239]:
plot(equation, 0, 2)
Out[239]:
x -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 -2.0 -1.9 -1.8 -1.7 -1.6 -1.5 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 -2 0 2 4 -2.0 -1.8 -1.6 -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8 4.0 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 -6.0 -5.8 -5.6 -5.4 -5.2 -5.0 -4.8 -4.6 -4.4 -4.2 -4.0 -3.8 -3.6 -3.4 -3.2 -3.0 -2.8 -2.6 -2.4 -2.2 -2.0 -1.8 -1.6 -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8 4.0 4.2 4.4 4.6 4.8 5.0 5.2 5.4 5.6 5.8 6.0 6.2 6.4 6.6 6.8 7.0 7.2 7.4 7.6 7.8 8.0 8.2 8.4 8.6 8.8 9.0 9.2 9.4 9.6 9.8 10.0 10.2 10.4 10.6 10.8 11.0 11.2 11.4 11.6 11.8 12.0 -10 0 10 20 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 f(x)

As is working with Open Data:

In [21]:
using DataFrames, Requests
INFO: Precompiling module Requests.
In [28]:
OPENDATA = get("https://data.stadt-zuerich.ch/dataset/stst_schulwesen/resource/e5ec0f06-46ef-4c49-872f-a18603e2d92b/download/tstst31.csv")
Out[28]:
Response(200 OK, 16 headers, 9641 bytes in body)
In [218]:
io = IOBuffer(readstring(OPENDATA))
T = readtable(io, separator=';')
T[1:4,:]
Out[218]:
StadtnameSchüler_Total_2010_2011Schüler_Total_2000_2001Schüler_Total_1990_1991Schüler_Vorschule_2010_2011Schüler_Obligatorische_Primar_und_Sekundarstufe_I_2010_2011Schüler_Sekundarstufe_II_Übergangsausbildung_Sek_I_Sek_II_2010_2011Schüler_Maturitätsschulen_2010_2011Schüler_Berufsausbildung_2010_2011Schüler_andere_allgemeinbildende_Schulen_2010_2011
1Basel261032845828327266412369109930416641289
2Bern316673072833151188091761031346715717396
3Genève33418330652964732831615993481504580312
4Lausanne29499296833014126001212274849338904192
In [99]:
"$(T[4,1]) had $(T[4,2]) kids in school in 2011"
Out[99]:
"Lausanne had 29499 kids in school in 2011"
In [219]:
string_to_float(str) = try parse(Int32, str) catch return(0) end
T[:Schüler_Total_2010_2011] = map(string_to_float, T[:Schüler_Total_2010_2011])
T[:Schüler_Maturitätsschulen_2010_2011] = map(string_to_float, T[:Schüler_Maturitätsschulen_2010_2011])
T[1:4]
Out[219]:
StadtnameSchüler_Total_2010_2011Schüler_Total_2000_2001Schüler_Total_1990_1991
1Basel261032845828327
2Bern316673072833151
3Genève334183306529647
4Lausanne294992968330141
5Winterthur229271982317510
6Zürich682606544462646
7Biel-Bienne105131116710161
8Lugano979168815094
9Luzern206781667315972
10St. Gallen184871968418711
11Baar239526172184
12Carouge (GE)274434612708
13Chaux-de-Fonds, La698067156275
14Chur934795898532
15Dietikon387533812735
16Dübendorf289126092386
17Emmen424644433635
18Frauenfeld494656874643
19Fribourg137491325112006
20Kriens265729812349
21Köniz483950244404
22Lancy1017082337802
23Meyrin262527972848
24Montreux353133272739
25Neuchâtel812475688313
26Rapperswil-Jona430929231936
27Renens (VD)236621511966
28Riehen208822141766
29Schaffhausen681574096768
30Sion11284102109842
In [230]:
plot(T[1:10, :], x=:Stadtname, y=Col.value(
        :Schüler_Total_2010_2011,
        :Schüler_Maturitätsschulen_2010_2011
    ), color=Col.index(
        :Schüler_Total_2010_2011,
        :Schüler_Maturitätsschulen_2010_2011
    )
)
Out[230]:
Stadtname Basel Bern Genève Lausanne Winterthur Zürich Biel-Bienne Lugano Luzern St. Gallen Schüler_Total_2010_2011 Schüler_Maturitätsschulen_2010_2011 Column -1.0×10⁵ -8.0×10⁴ -6.0×10⁴ -4.0×10⁴ -2.0×10⁴ 0 2.0×10⁴ 4.0×10⁴ 6.0×10⁴ 8.0×10⁴ 1.0×10⁵ 1.2×10⁵ 1.4×10⁵ 1.6×10⁵ 1.8×10⁵ -8.00×10⁴ -7.50×10⁴ -7.00×10⁴ -6.50×10⁴ -6.00×10⁴ -5.50×10⁴ -5.00×10⁴ -4.50×10⁴ -4.00×10⁴ -3.50×10⁴ -3.00×10⁴ -2.50×10⁴ -2.00×10⁴ -1.50×10⁴ -1.00×10⁴ -5.00×10³ 0 5.00×10³ 1.00×10⁴ 1.50×10⁴ 2.00×10⁴ 2.50×10⁴ 3.00×10⁴ 3.50×10⁴ 4.00×10⁴ 4.50×10⁴ 5.00×10⁴ 5.50×10⁴ 6.00×10⁴ 6.50×10⁴ 7.00×10⁴ 7.50×10⁴ 8.00×10⁴ 8.50×10⁴ 9.00×10⁴ 9.50×10⁴ 1.00×10⁵ 1.05×10⁵ 1.10×10⁵ 1.15×10⁵ 1.20×10⁵ 1.25×10⁵ 1.30×10⁵ 1.35×10⁵ 1.40×10⁵ 1.45×10⁵ 1.50×10⁵ 1.55×10⁵ 1.60×10⁵ -1×10⁵ 0 1×10⁵ 2×10⁵ -8.00×10⁴ -7.50×10⁴ -7.00×10⁴ -6.50×10⁴ -6.00×10⁴ -5.50×10⁴ -5.00×10⁴ -4.50×10⁴ -4.00×10⁴ -3.50×10⁴ -3.00×10⁴ -2.50×10⁴ -2.00×10⁴ -1.50×10⁴ -1.00×10⁴ -5.00×10³ 0 5.00×10³ 1.00×10⁴ 1.50×10⁴ 2.00×10⁴ 2.50×10⁴ 3.00×10⁴ 3.50×10⁴ 4.00×10⁴ 4.50×10⁴ 5.00×10⁴ 5.50×10⁴ 6.00×10⁴ 6.50×10⁴ 7.00×10⁴ 7.50×10⁴ 8.00×10⁴ 8.50×10⁴ 9.00×10⁴ 9.50×10⁴ 1.00×10⁵ 1.05×10⁵ 1.10×10⁵ 1.15×10⁵ 1.20×10⁵ 1.25×10⁵ 1.30×10⁵ 1.35×10⁵ 1.40×10⁵ 1.45×10⁵ 1.50×10⁵ 1.55×10⁵ 1.60×10⁵ y

If you have questions about this, please visit https://forum.schoolofdata.ch