Mean values depending on binning with respect to second variable

后端 未结 2 662
北海茫月
北海茫月 2021-02-10 00:15

I am working with python / numpy. As input data I have a large number of value pairs (x,y). I basically want to plot (x), i.e., the mean value

2条回答
  •  悲哀的现实
    2021-02-10 01:02

    If you can use pandas:

    import pandas as pd
    xedges = np.linspace(x.min(), x.max(), xbins+1)
    xedges[0] -= 0.00001
    xedges[-1] += 0.000001
    c = pd.cut(x, xedges)
    g = pd.groupby(pd.Series(y), c.labels)
    mean2 = g.mean()
    std2 = g.std(0)
    

提交回复
热议问题