How can I calculate the average weight in python for two columns (x,y) data file, between 8<r< 9. in python

I have tried this put it dose not work with my

np.average(X,Y, weights=[8,9])

I have calculated the average weight which is 12.14, now I am trying to use this weight to calculate the average fro the X, Y values??
How can I do so ?

this what I have tried to do , but I am still missing somthing which I do not know what is it?

def weighted(x, cols, w="weights"):
             return pd.Series(np.average(x[cols], weights=x[w], axis=0), cols)

 g.apply(weighted, ["column1", "column2"])           

sum(rate[g] * amount[g] / sum(amount) for g in range(len(rate)))
is one of the solution