4

Is there a way to adjust or change a setting that Polars would show a same number of decimal points for all values?

And if it is, am I able to save it as default for all new notebooks in Jupyter for instance?

For example,

pl.DataFrame({"a":[0.1213, 0.4244, 0.1000, 0.4242]})

Output: shape: (4, 1)

┌────────┐
│ a      │
│ ---    │
│ f64    │
╞════════╡
│ 0.1213 │
│ 0.4244 │
│ 0.1    │
│ 0.4242 │
└────────┘

I'd like to see the 0.1 as 0.1000

miroslaavi
  • 361
  • 2
  • 7

2 Answers2

0

I think right now we do not have this kind of options on the Polars API

If you take a look at https://pola-rs.github.io/polars/py-polars/html/reference/config.html

We only have limited options to format tables and strings.

0

This doesn't exactly answer your questions, but if the intention is just to print values to the same number of decimal points:

df = pl.DataFrame({"a":[0.1213, 0.4244, 0.1000, 0.4242]})

(
    df.lazy()
    .with_column(
        pl.col("a").round(4).cast(pl.Utf8).str.split(".")
    )
    .with_column(
        pl.col("a").arr.first().arr
        .concat(
            pl.col("a").arr.last().str.ljust(width=4, fillchar="0")
        ).arr.join(".")
    )
    .collect()
)
JGrant06
  • 53
  • 4