Question: I'm trying to select all columns of a DataFrame and perform multiple operations on each column using Polars. For example, I discovered that I can use the following code to count non-null values in each column: df.select(pl.col("*").is_not_null().sum()  However, when I attempt to concatenate multiple operations like this: ( df .select( pl.col("*").is_not_null().sum().alias("foo"), pl.col("*").is_null().sum().alias("bar") ) )  I encounter a Duplicated Error. This seems to happen because Polars tries to perform the operations but ends up using the same column names, which causes the duplication issue. To work around this, I'm currently using the following approach: a = ( df .select( pl.col("*").is_null().sum(), ) .transpose(include_header=True) .rename( {"column_0" : "null_count"} ) ) b = ( df .select( pl.col("*").is_not_null().sum(), ) .transpose(include_header=True) .rename( {"column_0" : "not_null_count"} ) ) a.join(b, how="left", on="column")  My goal is to generate an output that looks like this: shape: (8, 3) ┌─────────────┬────────────┬────────────────┐ │ column ┆ null_count ┆ not_null_count │ │ --- ┆ --- ┆ --- │ │ str ┆ u32 ┆ u32 │ ╞═════════════╪════════════╪════════════════╡ │ InvoiceNo ┆ 0 ┆ 541909 │ │ StockCode ┆ 0 ┆ 541909 │ │ Description ┆ 1454 ┆ 540455 │ │ Quantity ┆ 0 ┆ 541909 │ │ InvoiceDate ┆ 0 ┆ 541909 │ │ UnitPrice ┆ 0 ┆ 541909 │ │ CustomerID ┆ 135080 ┆ 406829 │ │ Country ┆ 0 ┆ 541909 │ └─────────────┴────────────┴────────────────┘ 

Answer: Let's use a simple test input df = pl.DataFrame({ "InvoiceNo": [1,2,3], "StockCode": [1,None,3], "Description": [None,None,6] })  To get your desired output, you can use  unpivot() to transpose the DataFrame. Also, you don't really need to calculate both values, as soon as you calculated count of null values, you can use len(df) - null_count to calculate not_null_count.  ( df .select(pl.all().is_null().sum()) .unpivot(variable_name="column", value_name="null_count") .with_columns(not_null_count = len(df) - pl.col.null_count) ) ┌──────────────┬────────────┬────────────────┐ │ column ┆ null_count ┆ not_null_count │ │ --- ┆ --- ┆ --- │ │ str ┆ u32 ┆ u32 │ ╞══════════════╪════════════╪════════════════╡ │ InvoiceNo ┆ 0 ┆ 3 │ │ StockCode ┆ 1 ┆ 2 │ │ Description ┆ 2 ┆ 1 │ └──────────────┴────────────┴────────────────┘  And if you want your result in non-unpivoted shape (as in, one row an multiple columns), you can use .name.suffix(): ( df .with_columns( pl.all().is_null().sum().name.suffix("_is_null"), pl.all().is_not_null().sum().name.suffix("_is_not_null") ) ) ┌───────────┬───────────┬──────────────┬───────────────┬───┬──────────────┬──────────────┬──────────────┬──────────────┐ │ InvoiceNo ┆ StockCode ┆ Description ┆ InvoiceNo_is_ ┆ … ┆ Description ┆ InvoiceNo_is ┆ StockCode_is ┆ Description │ │ --- ┆ --- ┆ --- ┆ null ┆ ┆ _is_null ┆ _not_null ┆ _not_null ┆ _is_not_null │ │ i64 ┆ i64 ┆ i64 ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │ │ ┆ ┆ ┆ u32 ┆ ┆ u32 ┆ u32 ┆ u32 ┆ u32 │ ╞═══════════╪═══════════╪══════════════╪═══════════════╪═══╪══════════════╪══════════════╪══════════════╪══════════════╡ │ 1 ┆ 1 ┆ null ┆ 0 ┆ … ┆ 2 ┆ 3 ┆ 2 ┆ 1 │ │ 2 ┆ null ┆ null ┆ 0 ┆ … ┆ 2 ┆ 3 ┆ 2 ┆ 1 │ │ 3 ┆ 3 ┆ 6 ┆ 0 ┆ … ┆ 2 ┆ 3 ┆ 2 ┆ 1 │ └───────────┴───────────┴──────────────┴───────────────┴───┴──────────────┴──────────────┴──────────────┴──────────────┘  And if you want several different aggregates, you can do unpivot() first: ( df .unpivot(variable_name="column") .group_by("column") .agg( not_null_count = pl.col.value.is_not_null().sum(), mean = pl.col.value.mean() ) ) ┌─────────────┬────────────────┬──────┐ │ column ┆ not_null_count ┆ mean │ │ --- ┆ --- ┆ --- │ │ str ┆ u32 ┆ f64 │ ╞═════════════╪════════════════╪══════╡ │ StockCode ┆ 2 ┆ 2.0 │ │ InvoiceNo ┆ 3 ┆ 2.0 │ │ Description ┆ 1 ┆ 6.0 │ └─────────────┴────────────────┴──────┘