generate and unnest a list column of random values in polars using np.random.binomial()
I am trying to generate arrays of varying length within a polars dataframe (i.e., a list column). For each cluster_id I would like to generate a series of 0s and 1s of length trials, which varies by cluster_id: import numpy as np import polars as pl from polars import col CLUSTERS = 200 MEAN_TRIALS = 20 MU = 0.5 SIGMA = 0.1 df_cluster = pl.DataFrame({'cluster_id': range(1, CLUSTERS+1)}) df_cluster = df_cluster.with_columns( mu = stats.truncnorm(a=0, b=1, loc=MU, scale=SIGMA).rvs(size=CLUSTERS), trials = np.random.poisson(lam=MEAN_TRIALS, size=CLUSTERS) ) I can use np.random.binomial() to gener
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.