First, I want to take random samples from three dataframes (150 rows each) and concat the results. Second, I want to repeat this process as many times as possible.
For part 1 I use the following function:
def get_sample(n_A, n_B, n_C):
A = df_A.sample(n = n_A, replace=False)
B = df_B.sample(n = n_B, replace=False)
C = df_C.sample(n = n_C, replace=False)
return pd.concat([A, B, C])
For part 2 I use the following line:
results = [get_sample(5,5,3) for i in range(n)]
Currently with n = 50.000 the analysis takes about 1 minute and 40 seconds on my MacBook. Any advise on how to improve the speed of this process is welcome!
PM the three dataframes (df_A, df_B, df_C) differ only in one categorical feature. The challenge is that I want a specific number samples from each category.