【发布时间】:2022-01-22 11:33:56
【问题描述】:
假设我有一个按以下比例(%)除以国籍的人口:
percentages = {'Germany': 0.4, 'France': 0.25, 'Greece': 0.15, 'Poland': 0.1, 'Norway': 0.05, 'Others': 0.05}
现在我需要从这个总体中生成样本。 Python 中有没有办法从总体中生成大小为 n 的样本?
例如,如果n = 50,我希望有类似的东西:
sample = {'Germany': 22, 'France': 10, 'Greece': 8, 'Poland': 6, 'Norway': 3, 'Others': 1}
【问题讨论】:
-
这能回答你的问题吗? A weighted version of random.choice