3对price字段进行分区处理按100、200、400、800、1600、3200、6400、12800、12800以上进行分区并删除异常值 4使用dfcatcode函数对价格区间进行标定
- 对price字段进行分区处理按100、200、400、800、1600、3200、6400、12800、12800以上进行分区,并删除异常值:
bins = [0, 100, 200, 400, 800, 1600, 3200, 6400, 12800, np.inf]
labels = ['0-100', '100-200', '200-400', '400-800', '800-1600', '1600-3200', '3200-6400', '6400-12800', '12800+']
df['price_range'] = pd.cut(df['price'], bins=bins, labels=labels, right=False)
df = df[df['price_range'].notna()]
- 使用df.cat.codes函数对价格区间进行标定:
df['price_code'] = df['price_range'].cat.codes
原文地址: https://www.cveoy.top/t/topic/FRW 著作权归作者所有。请勿转载和采集!