Answers for "random sample a dataframe"

0

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)
Posted by: Guest on May-12-2021
10

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
Posted by: Guest on April-13-2020
1

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'))
Posted by: Guest on October-08-2020
3

pandas sample

>>> df['num_legs'].sample(n=3, random_state=1)
fish      0
spider    8
falcon    2
Name: num_legs, dtype: int64
Posted by: Guest on June-17-2020

Code answers related to "random sample a dataframe"

Python Answers by Framework

Browse Popular Code Answers by Language