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)
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)
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
create random dataframe pandas
import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
pandas sample
>>> df = pd.DataFrame({'num_legs': [2, 4, 8, 0],
... 'num_wings': [2, 0, 0, 0],
... 'num_specimen_seen': [10, 2, 1, 8]},
... index=['falcon', 'dog', 'spider', 'fish'])
>>> df
num_legs num_wings num_specimen_seen
falcon 2 2 10
dog 4 0 2
spider 8 0 1
fish 0 0 8
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us