Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Julia implementation #52

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,224 changes: 1,224 additions & 0 deletions soln-julia/chap01.ipynb

Large diffs are not rendered by default.

766 changes: 766 additions & 0 deletions soln-julia/chap02.ipynb

Large diffs are not rendered by default.

1,618 changes: 1,618 additions & 0 deletions soln-julia/chap03.ipynb

Large diffs are not rendered by default.

2,872 changes: 2,872 additions & 0 deletions soln-julia/chap04.ipynb

Large diffs are not rendered by default.

2,613 changes: 2,613 additions & 0 deletions soln-julia/chap05.ipynb

Large diffs are not rendered by default.

2,625 changes: 2,625 additions & 0 deletions soln-julia/chap06.ipynb

Large diffs are not rendered by default.

3,353 changes: 3,353 additions & 0 deletions soln-julia/chap07.ipynb

Large diffs are not rendered by default.

4,152 changes: 4,152 additions & 0 deletions soln-julia/chap08.ipynb

Large diffs are not rendered by default.

3,863 changes: 3,863 additions & 0 deletions soln-julia/chap09.ipynb

Large diffs are not rendered by default.

4,267 changes: 4,267 additions & 0 deletions soln-julia/chap10.ipynb

Large diffs are not rendered by default.

6,306 changes: 6,306 additions & 0 deletions soln-julia/chap11.ipynb

Large diffs are not rendered by default.

4,740 changes: 4,740 additions & 0 deletions soln-julia/chap12.ipynb

Large diffs are not rendered by default.

5,291 changes: 5,291 additions & 0 deletions soln-julia/chap13.ipynb

Large diffs are not rendered by default.

4,160 changes: 4,160 additions & 0 deletions soln-julia/chap14.ipynb

Large diffs are not rendered by default.

4,416 changes: 4,416 additions & 0 deletions soln-julia/chap15.ipynb

Large diffs are not rendered by default.

4,897 changes: 4,897 additions & 0 deletions soln-julia/chap16.ipynb

Large diffs are not rendered by default.

4,486 changes: 4,486 additions & 0 deletions soln-julia/chap17.ipynb

Large diffs are not rendered by default.

3,262 changes: 3,262 additions & 0 deletions soln-julia/chap18.ipynb

Large diffs are not rendered by default.

5,647 changes: 5,647 additions & 0 deletions soln-julia/chap19.ipynb

Large diffs are not rendered by default.

14,556 changes: 14,556 additions & 0 deletions soln-julia/chap20.ipynb

Large diffs are not rendered by default.

708 changes: 708 additions & 0 deletions soln-julia/empiricaldist.jl

Large diffs are not rendered by default.

1,800 changes: 1,800 additions & 0 deletions soln-julia/redline.ipynb

Large diffs are not rendered by default.

78 changes: 78 additions & 0 deletions soln-julia/utils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@

module Utils
# check that a package is installed
function checkpkgs(pkglist::Vararg{AbstractString, N}) where N
missing = []
for p in pkglist
pkg = Symbol(p)
try
@eval using $pkg
catch e
push!(missing, p)
end
end
if length(missing) > 0
m = join(missing, ", ")
error("""These packages are missing: $m
You can install with e.g. :
import Pkg; Pkg.add("$(missing[1])")
"""
)
end
end

checkpkgs("Downloads", "Plots", "Distributions", "DataFrames", "Loess", "Gumbo", "HTTP", "Cascadia")

import Downloads, DataFrames, Loess, Plots, Distributions
import Gumbo, Cascadia, HTTP, CSV

function getfile(url::String)
filename = basename(url)
if !isfile(filename)
_local = Downloads.download(url, filename)
println("Downloaded ", _local)
end
end

default(linewidth=2, legend=false, size = (480, 320));

function Base.transpose(df::DataFrame; col_names=nothing)
tdf = DataFrames.DataFrame(collect.(eachrow(df)), :auto)
isnothing(col_names) || rename!(tdf, col_names)
return tdf
end

function plotloess!(xs, ys; kwargs...)
model = Loess.loess(xs, ys)
us = range(extrema(xs)...; length = 101)
vs = Loess.predict(model, us)
Plots.plot!(us, vs; kwargs...)
end

# this is a hack
# unfortunately, there's no Julia equivalent for Pandas' read_html
function retrievetables(url::String; kwargs...)
res = HTTP.request("GET",url)
g = Gumbo.parsehtml(String(res.body))

delim="∘"
tbls = eachmatch(Cascadia.Selector("tbody"), g.root)
v = []
for tbl in tbls
rows = children(tbl)
io = IOBuffer()
# this is an ugly hack: convert to CSV and let CSV deal with the mess
# (hopefully, parsing types correctly)
for row in rows
entries = [strip(nodeText(c)) for c in children(row)]
println(io, join(entries, delim))
end
seekstart(io)
df = CSV.File(io, delim=delim; kwargs...) |> DataFrame
push!(v, df)
end
return v
end

export checkpkgs, retrievetables, transpose, plotloess!, getfile
end;