0

I couldn't find a function that would summarize the content in the polars dataframe just like glimpse and summary do it in R?

aajkaltak
  • 1,437
  • 4
  • 20
  • 28

1 Answers1

4

Polars has a describe method:

df = pl.DataFrame({
    'a': [1.0, 2.8, 3.0],
    'b': [4, 5, 6],
    "c": [True, False, True]
    })

df.describe()
shape: (5, 4)
╭──────────┬───────┬─────┬──────╮
│ describe ┆ a     ┆ b   ┆ c    │
│ ---      ┆ ---   ┆ --- ┆ ---  │
│ str      ┆ f64   ┆ f64 ┆ f64  │
╞══════════╪═══════╪═════╪══════╡
│ "mean"   ┆ 2.267 ┆ 5   ┆ null │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┤
│ "std"    ┆ 1.102 ┆ 1   ┆ null │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┤
│ "min"    ┆ 1     ┆ 4   ┆ 0.0  │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┤
│ "max"    ┆ 3     ┆ 6   ┆ 1    │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┤
│ "median" ┆ 2.8   ┆ 5   ┆ null │

Which reports, like R's summary, descriptive statistics per column. I have not used glimpse before, but a quick Google suggests it does something similar to Polar's head, but then with the output stacked vertically, so it is easier to digest when there are many columns.

jvz
  • 1,183
  • 6
  • 13
  • 1
    Update: I have added glimpse to Polars here: https://github.com/pola-rs/polars/pull/5622 – jvz Dec 10 '22 at 12:41