我想根据其他列的值填充列的空值。 如果其他列为0,我想将其填充为0,否则将其保留为null。
A B C
1 1 0
0 NAN 2
2 NAN 0
I want the result as
A B C
1 1 0
0 NAN 2
2 0 0
答案 0 :(得分:0)
这应该可以解决问题:
df['B'] = np.where(df['C']== 0, 0, np.nan)
答案 1 :(得分:0)
我正在使用np.where
df['B']=np.where(df.B.isnull()&df.C.eq(0),0,df.B)