Answers for "how to sample dataframe in python"

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

sample based on column pandas

df1 = df[df['a']==1].sample(n=50)
df0 = df[df['a']==0].sample(n=50)
print(pd.concat([df1,df0]))
Posted by: Guest on December-03-2020

Code answers related to "how to sample dataframe in python"

Python Answers by Framework

Browse Popular Code Answers by Language