这是因为你没有把它们保存到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])