Random sampling without replacement

To compute random sampling without replacement, follow these steps:

  1. To perform random sampling without replacement, we first create a permutation array.
  2. Next, we slice off the first n elements of the array where n is the desired size of the subset you want to sample.
  3. Then we use the df.take() method to obtain actual samples:
df.take(np.random.permutation(len(df))[:3])

The output of the preceding code is as follows:

Note that in the preceding code, we only specified a sample of size 3. Hence, we only get three rows in the random sample. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.142.56