Created
December 13, 2025 16:01
-
-
Save Proteusiq/f690f6afbdb3ac4d74b07974937ac5a9 to your computer and use it in GitHub Desktop.
birds of feathers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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