3

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!

ℕʘʘḆḽḘ
  • 18,566
  • 34
  • 128
  • 235
  • Please try to use correct upper case letters, e.g. in the beginning of your title, sentences or the word "I". This would be gentle to your readers. – buhtz Mar 20 '23 at 12:56
  • 1
    It looks like `display.expand_frame_repr` is the important option which tells pandas to *"wrap-around across multiple pages if its width exceeds display.width"* - I don't think polars has such functionality yet. – jqurious Mar 20 '23 at 13:02
  • that would be a really useful feature. Most of us work with dataframe containing dozens of dataframe. the ability to see all columns at once is really important – ℕʘʘḆḽḘ Mar 20 '23 at 13:45
  • Have you found a solution for this issue? If not, how are you handling it? Just asked something similar at https://stackoverflow.com/questions/76639935/polars-x-pandas-dataframe-printed-at-ipython-console-in-spyder-ide – Danilo Setton Jul 08 '23 at 07:56

1 Answers1

4

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