Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Data transform with Smart Cell

livebooks/explorer/data_transform.livemd

Data transform with Smart Cell

Mix.install([
  {:kino_explorer, "~> 0.1"}
])

Prepare Data

require Explorer.DataFrame
df = Explorer.Datasets.fossil_fuels()

Smart Cells

processed_df =
  df
  |> Explorer.DataFrame.to_lazy()
  |> Explorer.DataFrame.group_by("country")
  |> Explorer.DataFrame.summarise(
    total_mean: mean(total),
    liquid_fuel_mean: mean(liquid_fuel),
    solid_fuel_mean: mean(solid_fuel),
    gas_fuel_mean: mean(gas_fuel)
  )
  |> Explorer.DataFrame.sort_by(asc: total_mean)
processed_df
df
|> Explorer.DataFrame.to_lazy()
|> Explorer.DataFrame.filter(year >= 2011)
|> Explorer.DataFrame.discard([
  "bunker_fuels",
  "cement",
  "gas_flaring",
  "liquid_fuel",
  "gas_fuel",
  "per_capita",
  "solid_fuel"
])
|> Explorer.DataFrame.collect()
|> Explorer.DataFrame.pivot_wider("year", "total")