【发布时间】:2019-05-25 19:28:24
【问题描述】:
首先,我想从三个数据帧(每个 150 行)中抽取随机样本并连接结果。其次,我想尽可能多地重复这个过程。
对于第 1 部分,我使用以下函数:
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])
对于第 2 部分,我使用以下行:
results = [get_sample(5,5,3) for i in range(n)]
目前在我的 MacBook 上使用 n = 50.000 进行分析大约需要 1 分 40 秒。欢迎任何有关如何提高此过程速度的建议!
PM 三个数据帧(df_A、df_B、df_C)仅在一个分类特征上有所不同。挑战在于我想要从每个类别中获取特定数量的样本。
【问题讨论】:
标签: python pandas performance random