通过gt( >)创建布尔掩码,然后将其转换为integers:
df = pd.DataFrame({'col':[.4,0.5,.1]})
threshold = .2
df['new'] = df['col'].gt(threshold).astype(int)
print (df)
col new
0 0.4 1
1 0.5 1
2 0.1 0
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1191 次 |
| 最近记录: |