vendredi 14 mai 2021

generate sample of numbers within range random amount of times in chronological order

I have a list of 5000 ids, and I want to generate a number between

ids = range(1,5000)
ids = list(itertools.chain.from_iterable(itertools.repeat(x, 1) for x in ids)) 

I want to add a new column with a number in chronological order between 1 and 50 per id. The number should occur a semi random amount of times, for instance like this

The expected output should be something like


a = [1] * 10
b = [2] * 32
c = [3] * 98
d = [4] * 239
e = [5] * 187
.... 
xx = [50] * 2876

but i am sure there must be a better way

Thank you!




Aucun commentaire:

Enregistrer un commentaire