给定数据框:coords x y likelihood0 197.486369 4.545954 3.890000e-071 319.946460 191.035224 2.360000e-072 319.880388 191.012984 2.740000e-073 320.286005 190.843329 2.170000e-074 320.210989 190.863304 2.490000e-075 320.212529 190.867178 2.310000e-07... ... ... ...10461 349.995217 303.397438 9.999956e-0110462 349.109666 305.710711 9.665585e-0110463 352.142571 310.081763 9.994751e-0110464 351.916488 317.078128 1.792100e-0210465 353.809847 320.086683 9.277161e-0110466 349.233529 321.859424 9.466683e-03我怎么能x;如果布尔数组中的相应索引为 True,则 y 值为 NaN。
1 回答
蝴蝶不菲
TA贡献1810条经验 获得超4个赞
假设您的布尔数组如下所示:
arr = np.array([True, False, True, False, True, False])
使用 loc:
df.loc[arr, ['x', 'y']] = np.nan
coords x y likelihood
0 0 NaN NaN 3.890000e-07
1 1 319.946460 191.035224 2.360000e-07
2 2 NaN NaN 2.740000e-07
3 3 320.286005 190.843329 2.170000e-07
4 4 NaN NaN 2.490000e-07
5 5 320.212529 190.867178 2.310000e-07
添加回答
举报
0/150
提交
取消