-1

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?

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Dila
  • 649
  • 1
  • 10
  • `df['ID'].sample(n = 3).tolist()`? – David Arenburg Sep 06 '22 at 21:20
  • If I just google the question title, the first result is [pandas.Series.sample — pandas 1.4.4 documentation](https://pandas.pydata.org/docs/reference/api/pandas.Series.sample.html). Please start with your own research in the future. See [ask]. – wjandrea Sep 06 '22 at 21:29

2 Answers2

2

I think you're looking for:

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

Docs: Series.sample()

wjandrea
  • 28,235
  • 9
  • 60
  • 81
lummers
  • 689
  • 3
  • 8
  • 17
0
sampled_list = random.sample(list(df['ID']), 3)