>>> df = pl.scan_csv("docs/assets/data/iris.csv") >>> ## OPTION 1 >>> # run SQL queries on frame-level >>> df.sql(""" ... SELECT species, ... AVG(sepal_length) AS avg_sepal_length ... FROM self ... GROUP BY species ... """).collect() shape: (3, 2) ┌────────────┬──────────────────┐ │ species ┆ avg_sepal_length │ │ --- ┆ --- │ │ str ┆ f64 │ ╞════════════╪══════════════════╡ │ Virginica ┆ 6.588 │ │ Versicolor ┆ 5.936 │ │ Setosa ┆ 5.006 │ └────────────┴──────────────────┘ >>> ## OPTION 2 >>> # use pl.sql() to operate on the global context >>> df2 = pl.LazyFrame({ ... "species": ["Setosa", "Versicolor", "Virginica"], ... "blooming_season": ["Spring", "Summer", "Fall"] ...}) >>> pl.sql(""" ... SELECT df.species, ... AVG(df.sepal_length) AS avg_sepal_length, ... df2.blooming_season ... FROM df ... LEFT JOIN df2 ON df.species = df2.species ... GROUP BY df.species, df2.blooming_season ... """).collect()