【发布时间】:2014-12-16 18:20:35
【问题描述】:
我有这样的日子:
eventday_idxs
2005-01-07 00:00:00
2005-01-31 00:00:00
2005-02-15 00:00:00
2005-04-18 00:00:00
2005-05-11 00:00:00
2005-08-12 00:00:00
2005-08-15 00:00:00
2005-09-06 00:00:00
2005-09-19 00:00:00
2005-10-12 00:00:00
2005-10-13 00:00:00
2005-10-20 00:00:00
2006-01-10 00:00:00
2006-01-30 00:00:00
2006-02-10 00:00:00
2006-03-29 00:00:00
我想在 AAPL 股票数据集上像这样计算 From : To 范围。
因为我是 Pandas 的初学者,所以我使用循环并这样做。
aap1_10_years = pd.io.data.get_data_yahoo('AAPL',
start=datetime.datetime(2004, 12, 10),
end=datetime.datetime(2014, 12, 10))
one_day = timedelta(days=1)
for i,ind in enumerate(eventday_idxs):
try:
do_calculations(aapl_10_years[ ind: eventday_idxs[i+1] - one_day ]['High'])
except IndexError:
do_calculations(aapl_10_years[ ind:]['High'] )
如何在没有这样的循环的情况下应用do_calcuations?因为这样的循环在 panda 中是不鼓励的,因为速度很慢,对吧?
【问题讨论】:
标签: python function loops pandas functional-programming