我得到了三个csv文件,一个包含标准普尔500指数成份股公司,另外两个包含它们的成交量和回报数据。如何在Python中从这500家公司中随机选择100家公司
from random import seed
from random import choice
seed(2)
numbers = [i for i in range(100)]
print(data)
for _ in range(50):
selection = choice(numbers)
print(selection)发布于 2019-11-12 07:29:22
使用random.choice()可能会导致重复的样本,因为它是带有替换的随机抽样。
试试这个:
从另一个列表中创建具有指定数量的随机元素的新列表。
from random import sample
numbers = [i for i in range(500)]
hundred_selected_numbers = sample(numbers, 100)https://stackoverflow.com/questions/58808990
复制相似问题