How to choose 3 random numbers from a pandas.series object?

Question:

I have a pandas.core.series.Series object that looks like this:

6          7
8          9
18        19
35        36
42        43

I want to get a list of 3 randomly chosen numbers from this list. I tried following the advice here and tried

sampled_list = random.sample(df['ID'], 3)

with no luck. Any suggestions?

Asked By: Dila

||

Answers:

sampled_list = random.sample(list(df['ID']), 3)
Answered By: Dalmas Otieno

I think you’re looking for:

df['ID'].sample(3).tolist()

Docs: Series.sample()

Answered By: lummers
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.