def compute_group(cls, data, scales, **params):
labels = ['x', 'y']
X = np.array(data[labels])
res = boxplot_stats(X, whis=params['coef'], labels=labels)[1]
try:
n = data['weight'].sum()
except KeyError:
n = len(data['y'])
if len(np.unique(data['x'])) > 1:
width = np.ptp(data['x']) * 0.9
else:
width = params['width']
if pdtypes.is_categorical(data['x']):
x = data['x'].iloc[0]
else:
x = np.mean([data['x'].min(), data['x'].max()])
d = {'ymin': res['whislo'],
'lower': res['q1'],
'middle': [res['med']],
'upper': res['q3'],
'ymax': res['whishi'],
'outliers': [res['fliers']],
'notchupper': res['med']+1.58*res['iqr']/np.sqrt(n),
'notchlower': res['med']-1.58*res['iqr']/np.sqrt(n),
'x': x,
'width': width,
'relvarwidth': np.sqrt(n)}
return pd.DataFrame(d)
评论列表
文章目录