我的数据框如下所示:
question timeSpent
a 5354
b 2344
c 2555
d 5200
e 3567
我想添加一个额外的列Score
,它包含0
和1
之间的值。timeSpent
(以秒表示)越大,Score
越接近0。如果花费的时间较小,则Score
接近1
如果timeSpent
小于或等于2500
,则假设该值为1
。然后每经过100
秒,它就会下降20%
。如果它达到或大于5500
,它将保持在0
所以对于2600
,分数是0.8
,对于2700
,分数是0.64
,等等
我为每个时间间隔编写if-else语句,但我认为必须有一种更快的方法来完成
您可以创建一个函数来计算分数,并将其应用于每个
timeSpent
输出:
相关问题 更多 >
编程相关推荐