Exploring Explorer
Mix.install([
{:req, "~> 0.4.4"},
{:explorer, "~> 0.7.1"},
{:kino_explorer, "~> 0.1.11"}
])
Baseball
resp =
Req.get!(
"https://raw.githubusercontent.com/westbaystars/first-pitch-homeruns/main/balls-in-play-2022.tsv"
)
require Explorer.DataFrame, as: DF
baseball = DF.load_csv!(resp.body, delimiter: "\t")
require Explorer.DataFrame
grouped =
baseball
|> Explorer.DataFrame.lazy()
|> Explorer.DataFrame.new(lazy: true)
|> Explorer.DataFrame.filter(col("Pitches") == 1 and col("Result") == "home-run")
|> Explorer.DataFrame.group_by(["Player", "Team"])
|> Explorer.DataFrame.summarise(Result_count: count(col("Result")))
|> Explorer.DataFrame.arrange(desc: col("Result_count"))
|> Explorer.DataFrame.collect()
grouped
|> DF.rename(Result_count: "HR")
|> DF.arrange(desc: col("HR"))
|> DF.head(10)