我对熊猫(和python ...和编程)相对较新,我试图做一个蒙特卡洛模拟,但我一直没能找到一个解决方案,需要一个合理的数量时间随机采样与熊猫数据帧
的数据存储在一个名为“YTDSales”它有每天的销售数据帧,每个产品
Date Product_A Product_B Product_C Product_D ... Product_XX
01/01/2014 1000 300 70 34500 ... 780
02/01/2014 400 400 70 20 ... 10
03/01/2014 1110 400 1170 60 ... 50
04/01/2014 20 320 0 71300 ... 10
...
15/10/2014 1000 300 70 34500 ... 5000
什么,我想要做的是模拟不同的情形,使用的休息年份(从10月15日到年底)每个产品的历史分布。例如与给出的数据,我会想,以填补今年余下时间在20至1100
之间销售我所做的是以下
# creates range of "future dates"
last_historical = YTDSales.index.max()
year_end = dt.datetime(2014,12,30)
DatesEOY = pd.date_range(start=last_historical,end=year_end).shift(1)
# function that obtains a random sales number per product, between max and min
f = lambda x:np.random.randint(x.min(),x.max())
# create all the "future" dates and fill it with the output of f
for i in DatesEOY:
YTDSales.loc[i]=YTDSales.apply(f)
解决方案的工作,但需要约3秒,这是很多,如果我打算重复1000次......有没有办法迭代?
感谢