python箱型图的返回值

今天,搞了一天的pyhton箱型图,头昏眼花,所幸终于搞定了,这里主要想记录下python箱型图的25%,50%,75%分位的计算,以及dataframe.boxplot()的返回值。
首先25%,50%,75%分为这些统计参数没法通过箱型图相关的方法得到,也没必要通过这些方法得到,可以直接用dataframe.describe()方法得到,清晰快捷,并且返回值也是dataframe,可以说是非常sweet了。
接下来说说boxplot()的返回值,通过以下的代码(片段)

    fig = plt.figure()
    box_fig = df_vol_deal.boxplot(return_type = 'dict')  #绘制7:00-7:15时间内的小时流量箱型图
    fig.tight_layout()  #自动调整横坐标,防止重叠
    plt.ylabel("各卡口小时流量/veh/hour")
    plt.xlabel("time")#我们设置横纵坐标的标题。
    x = box_fig['fliers'][0].get_xdata() # 'fliers'即为离群点的标签
    y = box_fig['fliers'][0].get_ydata()
    print(x)
    print('\n')
    print(y)

可以得到下面的返回值:

runfile('各卡口流量可视化输出.py', wdir='数据预处理')
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.
 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]


[1260.  672.  984.  752.  668. 1116.  684.  864. 1052.  688.  840. 1076.
 1700. 1288. 1104.  760. 1172. 1476.  980.  724.  828. 1556. 1532.  996.
  896. 1028.  696.  852.  732.  788.  636.  772.  712.  724.  952.  780.
  640.  840. 1032.  936. 1088. 1160. 1232. 1708.  644. 1140.]

其中第一个数组,其实我还没搞懂到底是啥意思,我猜测是dataframe中第几列的意思,大家可以继续去搞懂它,因为对我没啥用,就不深究了。
关键还是第二个数组,它返回的就是dataframe该列的离群值,因为前面代码中写了box_fig[‘fliers’][0],也就是0列的离群值的data。

发布了41 篇原创文章 · 获赞 40 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/qq_39805362/article/details/86761005