October 2019
Beginner to intermediate
674 pages
16h 43m
English
The sample() method can be used for the random sampling of a DataFrame or series. The parameters of the sample function support sampling across either axis and also sampling with and without replacement. For sampling, either the number of records to be sampled or the fraction of records to be sampled must be specified.
Let's sample three records from the Movie series:
sample_df["Movie"].sample(3)\
The following is the output:

Now, let's sample 50% of the columns from the DataFrame:
sample_df.sample(frac = 0.5, axis = 1)
The following is the output:
Read now
Unlock full access