calculate average of y values with different x values

岁酱吖の 提交于 2019-12-06 10:31:12
import numpy_indexed as npi
x = np.concatenate([x1,x2,x3,x4])
y = np.concatenate([y1,y2,y3,y4])
x_unique, y_mean = npi.group_by(x).mean(y)

Here's an alternative pandas solution:

import pandas as pd
pd.concat([pd.Series(y1,index=x1),
           pd.Series(y2,index=x2),
           pd.Series(y3,index=x3),
           pd.Series(y4,index=x4)], axis=1).mean(axis=1)
#0      1.0
#1      2.5
#2      4.0
#3      5.5
#..........
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!