Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

weighted averae multiple columns

In [11]: g.apply(lambda x: pd.Series(np.average(x[["var1", "var2"]], weights=x["weights"], axis=0), ["var1", "var2"]))
Out[11]:
               var1       var2
category
a         38.250000  34.000000
b         23.285714   6.428571
Source by www.javaer101.com #
 
PREVIOUS NEXT
Tagged: #weighted #averae #multiple #columns
ADD COMMENT
Topic
Name
5+2 =