I want to generate a list of say length 10000 from two items ('yes','no'). And the code I haev does that. The problem is, it generates ~50% yes and 50% no. How can I modify this code so that I can set the percentage of time it selects yes. Suppose i want yes like 36.7% of the time. And then it should select the remaining 'no' the remaining 63.3% time. Code is below:
import random
category = ('yes','no')
length_of_field = 10000
print(length_of_field)
print(type(category))
category_attribute = [random.choice(category) for _ in range(length_of_field)]
print('\ncategory:')
print(len(category_attribute))
print(type(category_attribute))
from collections import Counter
a= Counter(category_attribute).keys()
b= Counter(category_attribute).values()
print(a,b)
Aucun commentaire:
Enregistrer un commentaire