Py学习  »  pb.  »  全部回复
回复总数  1
5 年前
回复了 pb. 创建的主题 » Python更改列值-一次更改每一行

这是因为你没有把它们保存到df。另外,还有一个简洁的numpy Function np。where(),请参见 https://numpy.org/doc/1.20/reference/generated/numpy.where.html .

for i in range(0,len(df)):
  ul=upper_df.iloc[i]
  ll=lower_df.iloc[i]
  df.loc[i] = np.where(np.logical_or(df.loc[i] <= ll, df.loc[i] >= ul), 0, df.loc[i])