enter image description here 1。
def Age_makeup(Age):
if ((Age == 0) | (Age >= 60)):
return np.nan
else:
return Age
data["Age(clean)"] = data["Age"].apply(Age_makeup)
data[["Name","Age","Age(clean)"]].head()
enter image description here 2。
data.loc[(data["Age"] == 0) | (data["Age"] >= 60), ["Name","Age","Age(clean)"]].head()
我认为代码相同,结果也不同。 这些语法No.1和No.2有什么区别? enter image description here enter image description here