【问题标题】:average point on each bin pandas每个 bin pandas 的平均分
【发布时间】:2019-11-23 03:39:42
【问题描述】:

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

现在我为每台机器的 y vs 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 个分箱。

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

如何链接温度数据框 我是熊猫新手,我不知道该怎么做

【问题讨论】:

    标签: python pandas


    【解决方案1】:

    每 20 个掩码箱

    mask = my_df.index//20

    然后使用 groupby 和 agg

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

    【讨论】:

    • 所以 my_df 在这里是比率。温度呢,我没看出你在哪里考虑
    猜你喜欢
    • 1970-01-01
    • 2018-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-09
    相关资源
    最近更新 更多