datascience.tables.Table.sample

Table.sample(k=None, with_replacement=False, weights=None)[source]

Returns a new table where k rows are randomly sampled from the original table.

Kwargs:
k (int or None): If None (default), all the rows in the table are
sampled. If an integer, k rows from the original table are sampled.
with_replacement (bool): If False (default), samples the rows
without replacement. If True, samples the rows with replacement.
weights (list/array or None): If None (default), samples the rows
using a uniform random distribution. If a list/array is passed in, it must be the same length as the number of rows in the table and the values must sum to 1. The rows will then be sampled according the the probability distribution in weights.
Returns:
A new instance of Table.
>>> jobs = Table().with_columns([
...     'job',  ['a', 'b', 'c', 'd'],
...     'wage', [10, 20, 15, 8]])
>>> jobs
job  | wage
a    | 10
b    | 20
c    | 15
d    | 8
>>> jobs.sample() 
job  | wage
b    | 20
c    | 15
a    | 10
d    | 8
>>> jobs.sample(k = 2) 
job  | wage
b    | 20
c    | 15
>>> jobs.sample(k = 2, with_replacement = True,
...     weights = [0.5, 0.5, 0, 0]) 
job  | wage
a    | 10
a    | 10