上面有很多代码
。。。在
if c==excelfiles[1]:
b ==excelfiles[1]
wb = xlrd.open_workbook(a)
wb.sheet_names()
sh = wb.sheet_by_index(0)
for rownum in range(sh.nrows):
print sh.row_values(rownum)
for i in range(sheet.nrows):
cashflow = [sheet.cell_value(i,0)],[sheet.cell_value(i,1)],[sheet.cell_value(i,2)]
print cashflow
def npv(rate, cashflow):
value = cashflow[1] * ((1 + rate/100) ** (12 - cashflow[0]))
FV = 0
FV += value
return FV
def irr(cashflow, iterations = 100):
rate = 1.0
i = 0
while (cashflow[0][1] == 0):
i += 1
investment = cashflow[i][1]
for i in range(1, iterations+1):
rate *= (1 - (npv(rate, cashflow) / investment))
return rate
r = irr(cashflow)
print r
错误/输出:
^{pr2}$有人能解释一下为什么我的列表索引超出范围吗?你能告诉我怎么修理吗?我对python比较陌生,所以我肯定这是个愚蠢的错误。在
非常感谢!在
我还附上了代码:http://ideone.com/G5hGuK
在第10行的for循环中,
cashflow[0]
被设置为[sheet.cell_value(i,0)]
,这是一个长度为1的列表。表达式cashflow[0][1]
正试图读取该列表中的第二个值。在相关问题 更多 >
编程相关推荐