how to limit the display width in polars so that wide dataframes are printed in a legible way?

Question:

Consider the following example

pd.set_option('display.width', 50)

pl.DataFrame(data = np.random.randint(0,20, size = (10, 42)),
             columns = list('abcdefghijklmnopqrstuvwxyz123456789ABCDEFG')).to_pandas()

enter image description here

You can see how nicely the columns are formatted, breaking a line after column k so that the full dataframe is printed in chunks in the console. This was controlled by the pandas width argument above. I was not able to reproduce this behavior using polars and all the format options.

I have tried tweaking all possible settings:

pl.Config.set_tbl_cols(10)
pl.Config.set_fmt_str_lengths(10)
pl.Config.set_tbl_width_chars(70)
pl.Config.set_tbl_rows(2)
pl.Config.set_tbl_formatting('NOTHING')
pl.Config.set_tbl_column_data_type_inline(True)  
pl.Config.set_tbl_dataframe_shape_below(True) 

See below:

enter image description here

Any ideas? Thanks!

Asked By: ℕʘʘḆḽḘ

||

Answers:

You can display all frame columns like so…

with pl.Config() as cfg:
    cfg.set_tbl_cols(-1)
    print(df)

…which will give you a good result on the given frame if you have sufficient terminal/console/output width available. If this isn’t enough, I recommend making a feature request for this on the polars GitHub repository

Answered By: alexander-beedie
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.