繁体   English   中英

每个 bin 熊猫的平均点

[英]average point on each bin pandas

我有 2 个数据帧温度(y)和比率(x)。 在每个数据框中,我有 60 列对应于测量这两个参数的 60 台不同的机器。

现在我有一个 y 与 x 的每台机器的图,如下所示:

for column in ratio.columns:
    x = ratio[column]
    y = temperature[column]

    if len(x) != len(y):
        x_ind = x.index
        y_ind = y.index
        common_ind = x_ind.intersection(y_ind)
        x = x[common_ind]
        y = y[common_ind]

    plt.scatter(x,y)
    plt.savefig("plot" +column+".png")
    plt.clf()

因为我有很多数据点,所以我想对每台机器进行分箱并对每个分箱进行平均,以便每个分箱都有一个 y 的平均点。 x 介于 0 和 1 之间,我想每 0.05 进行一次分箱,从而得到 20 分箱。

我通过执行以下操作获得了每台机器的直方图: for x in ratio.columns: ratio.hist(column = x, bins = 20) 但这仅给出了事件数与比率的关系。

如何链接温度数据框我是熊猫的新手,但我不知道如何做到这一点

每 20 个口罩箱

mask = my_df.index//20

然后使用 groupby 和 agg

my_df.groupby(mask).agg(['mean'])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM