SFrame.sample(fraction, seed=None, exact=False)

Sample a fraction of the current SFrame’s rows.

fraction : float

Fraction of the rows to fetch. Must be between 0 and 1. if exact is False (default), the number of rows returned is approximately the fraction times the number of rows.

seed : int, optional

Seed for the random number generator used to sample.

exact: bool, optional

Defaults to False. If exact=True, an exact fraction is returned, but at a performance penalty.

out : SFrame

A new SFrame containing sampled rows of the current SFrame.


Suppose we have an SFrame with 6,145 rows.

>>> import random
>>> sf = SFrame({'id': range(0, 6145)})

Retrieve about 30% of the SFrame rows with repeatable results by setting the random seed.

>>> len(sf.sample(.3, seed=5))