【发布时间】:2016-01-08 15:05:32
【问题描述】:
我有两个数据框df_trade 和df_close,我想将它们的点积存储在ts_fund 中,但是ts_fund 是数组、数据框、向量等都没有关系。这两个数据帧将值和时间存储为datetime。例如df_trade:
2011-1-05 15 100
2011-1-20 10 200
和df_close
2011-1-05 1 .5
2011-1-20 .8 .1
所以我希望ts_fund 中的结果是:
2011-1-05 65
2011-1-20 28
我尝试了以下
ts_fund = np.zeros((len(ldt_timestamps), 1))
ts_fund = pd.DataFrame(ts_fund, index=ldt_timestamps, columns='portfolio value')
for index, row in df_trade.iterrows():
portfolio_value = np.dot(row.values.astype(float), df_close.ix[index].values)
ts_fund[index] = portfolio_value
但我得到了错误
TypeError: Index(...) must be called with a collection of some kind, 'portfolio value' was passed
如果我将ts_fund 设置为向量或数组而不是数据框会更容易吗?
【问题讨论】:
标签: python python-2.7 datetime pandas