1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| price_25 = data['租价/月'].quantile(0.25)
price_75 = data['租价/月'].quantile(0.75)
price_min = price_25 - 1.5*(price_75 - price_25) price_max = price_25 + 1.5*(price_75 - price_25)
data[data['租价/月'].map(lambda x:(x > price_max) or (x < price_min))]
ls1 = [] for i in range(len(data)): x = data['租价/月'].iloc[i] if x < price_min: ls1.append(np.nan) elif x > price_max: ls1.append(np.nan) else: ls1.append(x)
data['分位法'] = ls1 data[data['分位法'].isnull()]
data2 = data[data['分位法'].notnull()] data2 = data['分位法'].fillna(data['分位法'.mean()])
|