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
Post a Comment