When I try to use numpy.mean within a polars dataframe I get an error message:
import numpy as np #v2.1.0
import polars as pl #v1.6.0
from polars import col
TRIALS = 1
SIMS = 10
np.random.seed(42)
df = pl.DataFrame({
'a': np.random.binomial(TRIALS, .45, SIMS),
'b': np.random.binomial(TRIALS, .5, SIMS),
'c': np.random.binomial(TRIALS, .55, SIMS)
})
df.head()
df.with_columns(
z_0 = np.mean(col("a"))
).head()
TypeError: mean() got an unexpected keyword argument 'axis'
Adding an explicit axis argument will not change the error.
df.with_columns(
z_0 = np.mean(a=col("a"), axis=0)
).head()
TypeError: mean() got an unexpected keyword argument 'axis'
I know that I could complete this computation with:
df.with_columns(
z_0 = ncol("a").mean()
).head()
But I am trying to understand how non-polars functions work within polars.
16