Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 37 ยท Getting Started

Display Settings and Reading Output

Control how Polars prints tables with pl.Config: number of rows and columns, string width, table formatting, and how to read the shape and dtype header.

When you print a Polars DataFrame, you see a formatted table. That table is only a rendering of the data, and Polars shortens it so that big frames do not flood your screen. Knowing how to read the output, and how to change it, saves a lot of confusion, especially when you debug a pipeline.

Reading a printed table

A printed DataFrame has four parts:

  1. A header line, shape: (rows, columns).
  2. Column names on the first row of the grid.
  3. A second header row with each column's dtype (i64, f64, str, bool, date, list[i64], ...).
  4. The data rows. In long tables the middle is replaced by a row of โ€ฆ.
Python Truncated output

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Only the first and last five rows are shown; the shape line tells you all 100 rows are really there. Dtype abbreviations are lowercase in the grid (i64) while in code they are pl.Int64.

Changing the settings with pl.Config

pl.Config is a global settings object. Its methods can be used as a context manager so the change applies only inside a with block, or called once to change the setting for the whole session.

Python Show more rows temporarily

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Common settings:

Setting Meaning
tbl_rows Maximum rows printed before truncating
tbl_cols Maximum columns printed
fmt_str_lengths Longest string shown before it ends in an ellipsis
fmt_table_cell_list_len How many list items to show in a cell
tbl_hide_column_data_types Hide the dtype row
tbl_hide_dataframe_shape Hide the shape line
set_tbl_formatting("ASCII_FULL") Use plain ASCII borders instead of box-drawing characters
set_float_precision(n) Digits shown after the decimal point

Settings work as keyword arguments in pl.Config(...) or as method calls such as pl.Config.set_tbl_rows(20).

Python Formatting options

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The exact keyword names in pl.Config(...) follow the set_... method names (for example set_tbl_rows becomes tbl_rows=). If a name is rejected in your version, call pl.Config.set_tbl_rows(...) directly, or check help(pl.Config).

Turning data into other renderings

Besides print, you can change how a frame leaves Polars:

  • str(df) returns the table as a string, handy for logs and tests.
  • In a Jupyter notebook, a DataFrame displays as an HTML table. df.style (needs an extra package on a normal install) lets you format that HTML.
  • df.write_csv() with no path returns CSV text (and df.write_json() does the same for JSON on a normal install; the in-browser build leaves JSON out).
Python Strings and CSV

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Reproducible output

When you share an example or write a test, set the options explicitly at the top so everyone sees the same table:

Python
pl.Config.set_tbl_rows(10)
pl.Config.set_tbl_cols(8)
pl.Config.set_fmt_str_lengths(40)

You can also reset to defaults with pl.Config.restore_defaults().

Common pitfalls

  • "My rows are missing!" They are not. Check df.shape and raise tbl_rows.
  • Long strings look cut off. Raise fmt_str_lengths; the stored data is intact.
  • Floats look rounded. The grid shows a limited number of digits; the full precision is still stored. Use float_precision or df["col"].to_list() to see more.
  • Setting Config in a library. Global settings affect everything in the process. Prefer the with form in shared code.

Check your understanding

Quick check ยท 3 questions

of 3 answered You scored / 3 ยท perfect!

  1. 1. A printed DataFrame shows 10 rows with a row of 'โ€ฆ' in the middle and shape: (1000, 3). How many rows does the DataFrame hold?

    Printing truncates long tables. The shape line shows the real size, 1000 rows by 3 columns.
  2. 2. How do you change a display setting only for a few lines of code?

    pl.Config can be used with a with statement; the settings are restored when the block ends.
  3. 3. What does the setting fmt_str_lengths control?

    Long strings are cut with an ellipsis when printed; fmt_str_lengths sets where. The data itself is not changed.

Summary

  • A printed frame shows shape, column names, dtypes and (possibly truncated) rows.
  • pl.Config changes how many rows, columns and characters are shown, and the border style.
  • Use with pl.Config(...) to apply settings temporarily.
  • Printing only renders the data; the stored values are never changed.

Next: Core Contexts: select, filter and with_columns