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
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
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]))
pandas sample
>>> df['num_legs'].sample(n=3, random_state=1) fish 0 spider 8 falcon 2 Name: num_legs, dtype: int64
pandas create sample dataframe
>>> import pandas as pd >>> sentence = 'The quick brown fox jumps over a lazy dog.' >>> words = sentence.split(' ') >>> df1 = pd.DataFrame({'key': range(len(words)), ... 'column1_Words': words, ... 'column2_Length': [len(x) for x in words] ... }) >>> df1 key column1_Words column2_Length 0 0 The 3 1 1 quick 5 2 2 brown 5 3 3 fox 3 4 4 jumps 5 5 5 over 4 6 6 a 1 7 7 lazy 4 8 8 dog. 4 >>>
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