Python Forum
Confusion over df.sample()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Confusion over df.sample()
#1
Hi all,

Here's some code:

import matplotlib.pyplot as plt
import pandas as pd
import sys

count_a = 0
count_b = 0

die = pd.Series([2,4,6,8,10,12])
group = ['samp_a','samp_b']
while count_a < 1000 and count_b < 1000:
    samp_a = die.sample(10,replace=True)
 #   samp_b = die.sample(1)
    print(samp_a)
    print('samp_a type is {}'.format(type(samp_a)))
#    print(samp_b)
    sys.exit()
Here's some sample output:
0     2
2     6
5    12
3     8
3     8
5    12
2     6
4    10
0     2
4    10
dtype: int64
samp_a type is <class 'pandas.core.series.Series'>
With die only including 2, 4, 6, 8, 10, and 12, how am I getting odd numbers printed in the output?

Also, why am I getting samples of _two_ numbers each? How do I change this?
Reply


Messages In This Thread
Confusion over df.sample() - by Mark17 - Jan-15-2021, 07:02 PM
RE: Confusion over df.sample() - by Mark17 - Jan-15-2021, 07:06 PM
RE: Confusion over df.sample() - by buran - Jan-15-2021, 07:12 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020