plydata.one_table_verbs.sample_n¶
-
class
plydata.one_table_verbs.
sample_n
(*args, **kwargs)[source]¶ Sample n rows from dataframe
- Parameters
- data
dataframe
, optional Useful when not using the
>>
operator.- n
int
, optional Number of items from axis to return.
- replace
boolean
, optional Sample with or without replacement. Default = False.
- weights
str
or ndarray-like, optional Default 'None' results in equal probability weighting. If passed a Series, will align with target object on index. Index values in weights not found in sampled object will be ignored and index values in sampled object not in weights will be assigned weights of zero. If called on a DataFrame, will accept the name of a column when axis = 0. Unless weights are a Series, weights must be same length as axis being sampled. If weights do not sum to 1, they will be normalized to sum to 1. Missing values in the weights column will be treated as zero. inf and -inf values not allowed.
- random_state
int
ornumpy.random.RandomState
, optional Seed for the random number generator (if int), or numpy RandomState object.
- axis
int
orstring
, optional Axis to sample. Accepts axis number or name. Default is stat axis for given data type (0 for Series and DataFrames, 1 for Panels).
- data
Examples
>>> import pandas as pd >>> import numpy as np >>> rs = np.random.RandomState(1234567890) >>> df = pd.DataFrame({'x': range(20)}) >>> df >> sample_n(5, random_state=rs) x 5 5 19 19 14 14 8 8 17 17