【发布时间】:2021-09-10 00:06:52
【问题描述】:
我的数据框如下所示:
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 语句,但我认为必须有更快的方法来做到这一点。
【问题讨论】:
标签: python pandas dataframe percentage