0

I want to create a function create_bootstrap_sample (using X_train as input) that accepts Pandas DataFrame as a parameter and returns a bootstrap sample (also as a Pandas DataFrame).

def create_bootstrap_sample(df):
    pass

I wanted help with completing the code.

n53
  • 39
  • 3
  • This can be used for printing output print('-'*60) print('Number of rows should be the same:') print('Number of rows in X_train: ', X_train.shape[0]) print('Number of rows in bootstrap:', create_bootstrap_sample(X_train).shape[0]) print('-'*60) print('Row labels of bootstrap should have repeated values:') print('Contains repeat row labels:', bool(~create_bootstrap_sample(X_train).index.is_unique)) – n53 Mar 12 '21 at 04:26
  • Does this answer your question? [What is the purpose of the replace parameter for the sample function in pandas?](https://stackoverflow.com/questions/57095898/what-is-the-purpose-of-the-replace-parameter-for-the-sample-function-in-pandas) – StupidWolf Mar 12 '21 at 09:59

1 Answers1

0

This is basically the function that you need:

pandas.DataFrame.sample

Return a random sample of items from an axis of object.

It even contains this parameter:

replace: bool, default False

Allow or disallow sampling of the same row more than once.

xkudsraw
  • 149
  • 12