Description Of Data

There was a sudden surge in the amount of data.

There was a sudden spike in this table.

After comparing the data, we found some discrepancies that needed to be further investigated.

  • 7
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
def outliers_proc(data, col_name, scale = 3): # data:原数据 # col_name:要处理异常值的列名称 # scale:用来控制删除尺度的 def box_plot_outliers(data_ser, box_scale): iqr = box_scale * (data_ser.quantile(0.75) - data_ser.quantile(0.25)) # quantile是取出数据对应分位数的数值 val_low = data_ser.quantile(0.25) - iqr # 下界 val_up = data_ser.quantile(0.75) + iqr # 上界 rule_low = (data_ser < val_low) # 筛选出小于下界的索引 rule_up = (data_ser > val_up) # 筛选出大于上界的索引 return (rule_low, rule_up),(val_low, val_up) data_n = data.copy() data_series = data_n[col_name] # 取出对应数据 rule, values = box_plot_outliers(data_series, box_scale = scale) index = np.arange(data_series.shape[0])[rule[0] | rule[1]] # 先产生0到n-1,然后再用索引把其中处于异常值的索引取出来 print("Delete number is {}".format(len(index))) data_n = data_n.drop(index) # 整行数据都丢弃 data_n.reset_index(drop = True, inplace = True) # 重新设置索引 print("Now column number is:{}".format(data_n.shape[0])) index_low = np.arange(data_series.shape[0])[rule[0]] outliers = data_series.iloc[index_low] # 小于下界的值 print("Description of data less than the lower bound is:") print(pd.Series(outliers).describe()) index_up = np.arange(data_series.shape[0])[rule[1]] outliers = data_series.iloc[index_up] print("Description of data larger than the lower bound is:") print(pd.Series(outliers).describe()) fig, axes = plt.subplots(1,2,figsize = (10,7)) ax1 = sns.boxplot(y = data[col_name], data = data, palette = "Set1", ax = axes[0]) ax1.set_title("处理异常值前") ax2 = sns.boxplot(y = data_n[col_name], data = data_n, palette = "Set1", ax = axes[1]) ax2.set_title("处理异常值后") return data_n代码每一行解析
05-30

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值