random - generate categorical dataset in python -
suppose have list of ten cities :
["paris", "barcelona", "kolkata", "new york"]
how can simulate n random datasets of 2 attributes each having 2 cities selected above list:
["paris", "barcelona"] ["barcelona", "kolata"] ["new york", "paris"] ["paris", "barcelona"] ["new york", "paris"]
you can use random.sample
this
data = ["paris", "barcelona", "kolkata", "new york"] import random print [random.sample(data, 2) _ in xrange(5)]
Comments
Post a Comment