我想用两个不同列中的另外两个值替换两个不同列中的两个值。例如:
我想替换列value
中null
的所有值,其中列variable
中的值为name
,列source
中的值为a
。另外,我想保留replace值的来源
variable | value | source
name np.NaN a
name John b
email qq@g.com a
.... .... ....
预期产出:
variable | value | source
name John b
name John b
email qq@g.com a
.... .... ....
然后我就把复制品扔了。我正试图用np.where做这件事,但没有成功。 我不知道如何进行多重条件和多重替换
df['name'] = np.where(df['variable'] == 'name' and df['source'] == 'a' and df['value'].isnull(), ...)
也许有更优雅的方式来做到这一点。而且,性能越快越好
如果我理解得很好,这是一个解决方案:
相关问题 更多 >
编程相关推荐