我是Python新手,非常感谢您的帮助
我有一个包含2000行和2列的数据框:Row和Pct。 基本上,我想创建第三列,它将基于以下逻辑:
希望我能解释清楚:)
谢谢
编辑: 关于您的问题:
data = {
'Pct': [0.8,0.4,0.3,0.7,0.3,1,0.23,0.75,0.93,0.6],
'Row': [1,2,3,4,5,6,7,8,9,10]
}
df = pd.DataFrame(data, columns = ['Row','Pct'])
df
Row Pct
0 1 0.80
1 2 0.40
2 3 0.30
3 4 0.70
4 5 0.30
5 6 1.00
6 7 0.23
7 8 0.75
8 9 0.93
9 10 0.60
您可以这样做:
然后:
在运行上述函数之前检查“Pct”列的最小阈值也是一个好主意,因为您不想运行到无限循环中
相关问题 更多 >
编程相关推荐