Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I think you’re looking for:

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

Docs: Series.sample()

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading