Home > Mobile >  Display exponential values as float in Polars
Display exponential values as float in Polars

Time:12-24

I have some float columns in Polars df. Some values displays like 9.4036e15. How I can display it with normal digital view?

CodePudding user response:

You could .apply(str)

>>> df = pl.DataFrame({"a": [1, 2, 3], "b": [4, 5, 9.4036e15]})
>>> df.select(pl.all().apply(str))
shape: (3, 2)
┌─────┬────────────────────┐
│ a   | b                  │
│ --- | ---                │
│ str | str                │
╞═════╪════════════════════╡
│ 1   | 4.0                │
├─────┼────────────────────┤
│ 2   | 5.0                │
├─────┼────────────────────┤
│ 3   | 9403600000000000.0 │
└─────┴────────────────────┘

My first thought was to cast to a string - but it keeps the scientific notation:

>>> df.select(pl.all().cast(pl.Utf8))
shape: (3, 2)
┌─────┬───────────┐
│ a   | b         │
│ --- | ---       │
│ str | str       │
╞═════╪═══════════╡
│ 1   | 4.0       │
├─────┼───────────┤
│ 2   | 5.0       │
├─────┼───────────┤
│ 3   | 9.4036e15 │
└─────┴───────────┘
  • Related