Want to create column with random values from list

Solved!
pphanireddy007
Level 1
Want to create column with random values from list

Hi All,

I want to create column with random values from list.

List values = test1,test2,test3 etc

I want to insert above values randomly.

Example-

Column1(Coming from DB)           Random values

1                                                     Test1

2                                                    Test3

3                                                      Test1 

4                                                        Test2

5                                                      Test3


Operating system used: windows

0 Kudos
1 Solution
JuanE
Dataiker

You can do this in many ways. One that I think is neat is to use a Python processor in a Prepare step:

 

 

Capture.PNG

 

This is the sample code, modify it according to your needs as you see fit:

import random
def process(row):
    my_list = ["test1", "test2", "test3"]
    return random.choice(my_list)

 

View solution in original post

1 Reply
JuanE
Dataiker

You can do this in many ways. One that I think is neat is to use a Python processor in a Prepare step:

 

 

Capture.PNG

 

This is the sample code, modify it according to your needs as you see fit:

import random
def process(row):
    my_list = ["test1", "test2", "test3"]
    return random.choice(my_list)