on-internet
← Community

Add numpy random values to a Polars dataframe using a column as input to numpy.random?

Stack Overflow ·

Let's say I have a dataframe that has a column named mean that I want to use as an input to a random number generator. Coming from R, this is relatively easy to do in a pipeline: library(dplyr) tibble(alpha = rnorm(1000), beta = rnorm(1000)) %>% mutate(mean = alpha + beta) %>% bind_cols(random_output = rnorm(n = nrow(.), mean = .$mean, sd = 1)) #> # A tibble: 1,000 × 4 #> alpha beta mean random_output #> <dbl> <dbl> <dbl> <dbl> #> 1 0.231 -0.243 -0.0125 0.551 #> 2 0.213 0.647 0.861 0.668 #> 3 0.824 -0.353 0.471 0.852 #> 4 0.665 -0.916 -0.252 -1.81 #> 5 -0.850 0.384 -0.465 -3.90 #> 6 0.721 0.67

Comments

Sign in or sign up to comment and upvote.

No comments yet.