To compute random sampling without replacement, follow these steps:
- To perform random sampling without replacement, we first create a permutation array.
- Next, we slice off the first n elements of the array where n is the desired size of the subset you want to sample.
- 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.