get random sample from dataframe python code example
Example 1: pandas sample seed
>>> df.sample(frac=0.5, replace=True, random_state=1)
num_legs num_wings num_specimen_seen
dog 4 0 2
fish 0 0 8
Example 2: pandas random sample
# n: number of rows to be extracted randomly
# random_state fixed for reproducibility
# replace = True for extraction with replacement
df.sample(n=3, random_state=42, replace=False)