答案 0 :(得分:2)
当可以使用向量表达式来完成时,最好避免迭代数据帧。像这样的事情应该起作用,尽管对于您的特定情况可能需要按摩一下。
# Set your dataframe
df = ...
# Gets a boolean vector for positions where you have na in column b
nulls_in_b = df["b"].isna()
# Set the places where its null to values from column c
df["b"].loc[nulls_in_b] = df["c"].loc[nulls_in_b]