polars.Config.set_fmt_str_lengths#

classmethod Config.set_fmt_str_lengths(n: int | None) type[Config][source]#

Set the number of characters used to display string values.

Parameters:
nint

Number of characters to display.

Examples

>>> df = pl.DataFrame(
...     {
...         "txt": [
...             "Play it, Sam. Play 'As Time Goes By'.",
...             "This is the beginning of a beautiful friendship.",
...         ]
...     }
... )
>>> df.with_columns(pl.col("txt").str.len_bytes().alias("len"))
shape: (2, 2)
┌─────────────────────────────────┬─────┐
│ txt                             ┆ len │
│ ---                             ┆ --- │
│ str                             ┆ u32 │
╞═════════════════════════════════╪═════╡
│ Play it, Sam. Play 'As Time Go… ┆ 37  │
│ This is the beginning of a bea… ┆ 48  │
└─────────────────────────────────┴─────┘
>>> with pl.Config(fmt_str_lengths=50):
...     print(df)
shape: (2, 1)
┌──────────────────────────────────────────────────┐
│ txt                                              │
│ ---                                              │
│ str                                              │
╞══════════════════════════════════════════════════╡
│ Play it, Sam. Play 'As Time Goes By'.            │
│ This is the beginning of a beautiful friendship. │
└──────────────────────────────────────────────────┘