I am attempting to select a random integer from the list below using random.randint but it doesn't seem to work. Any ideas, please? The list goes from 0 to 229.
list(range(len(cleaned_df.loc[cleaned_df["Drug Regimen"]=="Capomulin"])))
Thanks!
CodePudding user response:
random.choice(your_list)
let's you choose random element from a list.
CodePudding user response:
You can use random.choice
:
import random
your_list = list(range(len(cleaned_df.loc[cleaned_df["Drug Regimen"]=="Capomulin"])))
random_number = random.choice(your_list)
CodePudding user response:
You could use randrange
from the random
package:
import random
upper_range_limit = len(cleaned_df.loc[cleaned_df["Drug Regimen"]=="Capomulin"])
rnd_number = random.randrange(0, upper_range_limit)
[
random.randrange()
returns] a randomly selected element from range(start, stop, step). This is equivalent to choice(range(start, stop, step)), but doesn’t actually build a range object. https://docs.python.org/3/library/random.html#random.randrange