我有一个带有日期,现金,名称,密钥列的数据框。我正在尝试通过对密钥进行分组来找到xirr。但是,当我运行代码时,出现错误“ TypeError:'float'对象不可调用”
f1['l'] = list(zip(f1["Date"], f1["Cash"]))
[![image][1]][1]
def xirr(transactions):
years = [(ta[0] - transactions[0][0]).days / 365.0 for ta in transactions]
residual = 1
step = 0.05
guess = 0.05
epsilon = 0.0001
limit = 10000
while abs(residual) > epsilon and limit > 0:
limit -= 1
residual = 0.0
for i, ta in enumerate(transactions):
residual += ta[1] / pow(guess, years[i])
if abs(residual) > epsilon:
if residual > 0:
guess += step
else:
guess -= step
step /= 2.0
return guess-1
print(xirr(f1['l'])) #till here it runs
f2 = f1.groupby('KEY').apply(xirr(f1['l'])) # this line is giving error