Skip to content

Instantly share code, notes, and snippets.

@Proteusiq
Created December 13, 2025 16:01
Show Gist options
  • Select an option

  • Save Proteusiq/f690f6afbdb3ac4d74b07974937ac5a9 to your computer and use it in GitHub Desktop.

Select an option

Save Proteusiq/f690f6afbdb3ac4d74b07974937ac5a9 to your computer and use it in GitHub Desktop.
birds of feathers
import ibis
conn = ibis.connect("duckdb://") # bigguery://, snowfalke://, etc
# load penguin data
penguins = conn.read_csv(
"https://raw.githubusercontent.com/mwaskom/seaborn-data/master/penguins.csv"
)
# query: find female penguins heavier than their species average
query = (
penguins
.mutate(
species_avg_weight=penguins.body_mass_g.mean().over(
ibis.window(group_by=penguins.species)
)
)
.filter(lambda t: (t.sex.lower() == "female") & (t.body_mass_g > t.species_avg_weight))
.select("species", "island", "body_mass_g", "species_avg_weight")
.order_by(ibis.desc("body_mass_g"))
)
# see results executed in db
print(query.execute())
# debug the SQL generated
print(ibis.to_sql(query))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment