IRR计算:ValueError:float()的文字无效:

时间:2018-02-14 05:41:24

标签: python numpy irr

我正在尝试计算IRR并且它在命令行中给出结果,但每当我尝试将值作为参数传递时,其失败并出现以下错误

代码

#shuffle

错误

请找出错误

import numpy
import sys   

def irrYearly(array):
    array = [array]
    irr = round(numpy.irr(array), 2)*100
    return irr
def irrCal(tenure, array):
    if tenure == "Yearly":
        # return irrYearly(array)
        # array = [-30000, -30000, -30000, -30000, -30000, 107180]  -- if I uncomment this line its works fine
        print(irrYearly(array))

    elif tenure == "Monthly":
        # return irrMonthly(array)
        print(irrMonthly(array))

def main():
    if len(sys.argv) == 3:
        tenure = sys.argv[1]
        array = sys.argv[2]
        irrCal(tenure, array)  

main()

1 个答案:

答案 0 :(得分:1)

argv[2]是一个以逗号分隔的值的字符串,但为了使它不是一个字符串而不是一个浮点列表。你首先需要像这样转换它: float_vals = [float(x) for x in argv[2].split(",")]