任务如下:
Add a new column to df called income10. It should contain the same values as income with all 0 values replaced with 1.
我试过下面的代码:
df['income10'] = np.where(df['income']==0, df['income10'],1)
但我一直收到错误:
请您参考如下方法:
您可以对列中的每个值应用一个函数:
df["a"] = df.a.apply(lambda x: 1 if x == 0 else x)
