有一个带有值的 df
df
0 1
sun NaN
moon 123
cat NaN
dog yatch
将已经存在的值转为通过,将 NaN 转为失败
预期输出
0 1
sun fail
moon pass
cat fail
dog pass
最佳答案
使用numpy.where
与 Series.isna
:
df[1] = np.where(df[1].isna(), 'fail', 'pass')
关于python - 数据框将现有列值更改为单个特定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59579377/