python - Select random row based on intervals -


is there function in python pandas randomly selects row based on values column in dataframe (function perform roulette wheel selection)?

i.e.

 id     value  1      1  2      2  3      3 

then chance 1/(1+2+3) row 1 selected, chance 2/6 row 2 , 3/6 row 3.

i know easy write own function random number between 0 , sum(value) , loop , select row wondering if there pre-defined function.

select index like:

i = choice(range(len(df)), df.value)

where choice whatever want here.

then use iloc.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -