#!/usr/bin/env python
# -*- coding:utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import json
from decimal import Decimal
# 保留浮点类型
jstring='{"name":"pro","price":12.05}'
str=json.loads(jstring,parse_float=Decimal)
print(str)
# 柱状图
def is_outlier(points,threshold=3.5):
if len(points.shape)==1:
points=points[:,None]
median=np.median(points,axis=0)
diff=np.sum((points-median)**2,axis=-1)
diff=np.sqrt(diff)
med_abs_deviation=np.median(diff)
modified_z_score=0.6745*diff/med_abs_deviation
return modified_z_score > threshold
x=np.random.random(10)
buckets=50
np.r_[x,-49,95,100,-100]
fitered=x[~is_outlier(x)]
plt.figure()
plt.subplot(211)
plt.hist(x,buckets)
plt.xlabel('Raw')
plt.subplot(212)
plt.hist(fitered,buckets)
plt.xlabel('Cleaned')
plt.show()
转载于:https://www.cnblogs.com/NiceTime/p/10125207.html