Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Polars how do I print all elements of a list column?

I have a Polars DataFrame with a list column. I want to control how many elements of a pl.List column are printed.

I've tried pl.pl.Config.set_fmt_str_lengths() but this only restricts the number of elements if set to a small value, it doesn't show more elements for a large value.

I'm working in Jupyterlab but I think it's a general issue.

import polars as pl

N = 5
df = (
    pl.DataFrame({
        "id": range(N)
    })
    .with_row_index("value")
    .rolling(
        "id", period=f"{N}i"
    )
    .agg(
        pl.col("value")
    )
)
shape: (5, 2)
┌─────┬─────────────┐
│ id  ┆ value       │
│ --- ┆ ---         │
│ i64 ┆ list[u32]   │
╞═════╪═════════════╡
│ 0   ┆ [0]         │
│ 1   ┆ [0, 1]      │
│ 2   ┆ [0, 1, 2]   │
│ 3   ┆ [0, 1, … 3] │
│ 4   ┆ [0, 1, … 4] │
└─────┴─────────────┘
like image 245
braaannigan Avatar asked Sep 12 '25 02:09

braaannigan


2 Answers

pl.Config.set_tbl_rows(100)

And more generally, I would try looking at dir(pl.Config)

like image 200
JohnRos Avatar answered Sep 13 '25 20:09

JohnRos


Release 0.19.9 added a new config setting to control how many List items are printed.

import polars as pl
    
pl.Config.set_fmt_table_cell_list_len(10)
    
pl.DataFrame({
  "my_lists": [range(n) for n in range(7)]
})

Output.

like image 41
Hericks Avatar answered Sep 13 '25 20:09

Hericks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!