Path: blob/main/docs/source/src/python/user-guide/lazy/schema.py
7890 views
# --8<-- [start:setup]1import polars as pl23# --8<-- [end:setup]45# --8<-- [start:schema]6lf = pl.LazyFrame({"foo": ["a", "b", "c"], "bar": [0, 1, 2]})78print(lf.collect_schema())9# --8<-- [end:schema]1011# --8<-- [start:lazyround]12lf = pl.LazyFrame({"foo": ["a", "b", "c"]}).with_columns(pl.col("foo").round(2))13# --8<-- [end:lazyround]1415# --8<-- [start:typecheck]16try:17print(lf.collect())18except Exception as e:19print(f"{type(e).__name__}: {e}")20# --8<-- [end:typecheck]2122# --8<-- [start:lazyeager]23lazy_eager_query = (24pl.LazyFrame(25{26"id": ["a", "b", "c"],27"month": ["jan", "feb", "mar"],28"values": [0, 1, 2],29}30)31.with_columns((2 * pl.col("values")).alias("double_values"))32.collect()33.pivot(index="id", on="month", values="double_values", aggregate_function="first")34.lazy()35.filter(pl.col("mar").is_null())36.collect()37)38print(lazy_eager_query)39# --8<-- [end:lazyeager]404142