如何在var1中随机选取3个变量,按'DATE'分组,求和,然后进行多次模拟?
df =
DATE var1
2023-01-31 1
2023-01-31 2
2023-01-31 3
2023-01-31 4
2023-01-31 5
2023-02-28 6
2023-02-28 7
2023-02-28 8
2023-02-28 9
2023-02-28 10
Simulation 1 =
2023-01-31 = (1+3+5) = 9
2023-02-28 = (6+7+10) = 23
simulation 2
2023-01-31 = (1+2+5) = 8
2023-02-28 = (9+7+10) = 26
simulation n.......
假设我们做了10次模拟
1条答案
按热度按时间k97glaaz1#
您可以将
groupby.agg
与sample
一起使用:示例输出:
如果要重复此过程,请使用循环:
根据重复采样创建DataFrame:
示例输出: