polars.DataFrame.mean#

DataFrame.mean(
*,
axis: int | None = None,
null_strategy: NullStrategy = 'ignore',
) Self | Series[source]#

Aggregate the columns of this DataFrame to their mean value.

Parameters:
axis

Either 0 (vertical) or 1 (horizontal).

Deprecated since version 0.19.14: This argument will be removed in a future version. This method will only support vertical aggregation, as if axis were set to 0. To perform horizontal aggregation, use mean_horizontal().

null_strategy{‘ignore’, ‘propagate’}

This argument is only used if axis == 1.

Deprecated since version 0.19.14: This argument will be removed in a future version.

Examples

>>> df = pl.DataFrame(
...     {
...         "foo": [1, 2, 3],
...         "bar": [6, 7, 8],
...         "ham": ["a", "b", "c"],
...         "spam": [True, False, None],
...     }
... )
>>> df.mean()
shape: (1, 4)
┌─────┬─────┬──────┬──────┐
│ foo ┆ bar ┆ ham  ┆ spam │
│ --- ┆ --- ┆ ---  ┆ ---  │
│ f64 ┆ f64 ┆ str  ┆ f64  │
╞═════╪═════╪══════╪══════╡
│ 2.0 ┆ 7.0 ┆ null ┆ 0.5  │
└─────┴─────┴──────┴──────┘