-1

I have a data frame with the customers as shown below.

df:

id      name     
1       john
2       dan
3       sam

also, I have a list as

['www.costco.com', 'www.walmart.com']

I would like to add a column named domain to df by randomly selecting the elements from the list.

Expected output:

id      name       domain
1       john       www.walmart.com
2       dan        www.costco.com
3       sam        www.costco.com

Note: since it is a random selection output may not be the same as always.

Danish
  • 2,533
  • 10
  • 21

1 Answers1

1

You can use random.choices:

import random
df['domain'] = random.choices(lst, k=len(df))

A sample output:

   id  name           domain
0   1  john  www.walmart.com
1   2   dan   www.costco.com
2   3   sam   www.costco.com