How to speed up the pandas group by sample?

I am currently picking 10% of the sample from pandas groupby and I am performing the same operation for 10 times.

for i in range(10):
    sampled = df.groupby(by=['month','year','id_n']).sample(frac=0.10, replace=True)

But each time, it is running for a very long time. Is there any alternative to make it real quick?

Thank you in advance

Read more here:

Content Attribution

This content was originally published by python_interest at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: