我正在尝试为我的数据帧实现以下算法:
if Tenure==0:
s=1
else:
s = (previous value from "s") * (1-previous value from "h")
列s
作为h
的函数计算,初始值为1。你知道吗
输入数据帧:
popt stopt popcum h s
Tenure
0.0 2383 508.0 5067890 0.000100 1
1.0 18358 17310.0 5065507 0.003417 0
2.0 16742 15103.0 5047149 0.002992 0
3.0 13298 11361.0 5030407 0.002258 0
4.0 9566 9522.0 5017109 0.001898 0
result3["s"]=result3.apply(funkcyjka)
为了跳过第一个条件,我刚刚编辑了第一行,因为它是唯一一个任期=0的行
我想到的是:
def funkcyjka(res):
x=0
lol=(res["s"].iloc[x])*(1-(res["h"].iloc[x]))
x+=1
return lol
但它并没有达到我的期望。如何将此函数实现到数据帧?你知道吗
如果你把它写在纸上,这就是为
s
的每一行实际计算的结果:所以,你需要
shift
+cumprod
这里:相关问题 更多 >
编程相关推荐