📜  使用掩码 pandas 创建新列 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:02.536000             🧑  作者: Mango

代码示例1
mask0 = (df['condition'] == 1)
mask1 = (df['condition'] == 0)

df.loc[mask0, 'newColumn'] = df.loc[mask0, 'otherColumn1']
df.loc[mask1, 'newColumn'] = df.loc[mask1, 'otherColumn2']