Cluster Sampling in Python

If I have 10 categories which have 1000 samples each; I want to sample 100 from each category randomly. Is there a library or method in python to do it?

If you have your data stored as pandas DataFrames, then you can use the df.sample() or Series.sample() methods to sample quickly.

If you got ten DataFrames, for example, you can do something like:

for df in dataframes:
    random_sample = df.sample(100)

Documentation:
DataFrame.sample()
Series.sample()

1 Like