[英]Creating new column in Pandas based on values from another column
您可以對列中的每個值應用 function:
df["a"] = df.a.apply(lambda x: 1 if x == 0 else x)
您正在嘗試引用一個尚不存在的列。
df['income10'] = np.where(df['income']==0, ===>**df['income10']**,1)
在您的 np.where 中,您需要引用值所在的列。 試試這個
df['income10'] = np.where(df['income']==0, 1, df['income'])
編輯:更正了 arguments 的順序
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.