Questions tagged [weighted-average]

The weighted average or weighted mean is similar to an arithmetic mean where instead of each of the data points contributing equally to the final average, some data points contribute more than others.

If all the weights are equal, then the weighted mean is the same as the arithmetic mean.

The mathematical expression for the weighted average is

enter image description here

Read more here

476 questions
2
votes
0 answers

PowerBI DAX how to exclude blanks from weighted average

I can build the weighted average via quick measure Average of columnA weighted by weight per Id = VAR __CATEGORY_VALUES = VALUES('table'[Id]) RETURN DIVIDE( SUMX( KEEPFILTERS(__CATEGORY_VALUES), …
2
votes
1 answer

aggregate irregular data to monthly averages weighing for days in months,using python

I am struggling to average my data into monthly mean taking into account that the data can represent two months (and years), and there are empty periods. Thus a need to weigh the samples accordantly, i.e. a sample with 2 days in one month and 5 in…
Wenche Aas
  • 21
  • 4
2
votes
2 answers

pmap columns by group to get weighted row-wise mean

I'm trying to get the weighted row mean of certain columns by group. library(tidyverse) set.seed(1) df <- data.frame(group = rep(LETTERS[3:4], each = 10), x = runif(n = 10, min = 10, max = 15), y = runif(n = 10, min = 100, max…
user63230
  • 4,095
  • 21
  • 43
2
votes
1 answer

Get average stock price in Google Sheets from a list

I'm trying to get average stock prices from a dynamic list. In my example, I've made a bought stocks in a few different days. And I've sold some of them (not all). So, I have some stocks available that I want to find out the average price: How to…
2
votes
2 answers

pandas pivot table: calculate weighted averages through aggfunc

I've got a pandas dataframe on education and income that looks basically like this. import pandas as pd import numpy as np data = { 'education': ['Low', 'High', 'High', 'Medium', 'Low', 'Low', 'High', 'Low', 'Medium', 'Medium'], 'income':…
JLP
  • 45
  • 5
2
votes
1 answer

Calculating weighted average in Pandas using NumPy function

Assume we have a pandas dataframe like this: a b id 36 25 2 40 25 3 46 23 2 40 22 5 42 20 5 56 39 3 I would like to perform a operation (a div b), then group by id and finally calculate a weighted average, using "a"…
mcatis
  • 1,176
  • 4
  • 11
  • 24
2
votes
2 answers

Calculate adjusted cost base using Python pandas ( Portfolio Analysis of Stocks Buy/Sell)

I am trying to do a portfolio analysis of my trading and trying to calculate the adjusted cost base price. I have tried almost everything but nothing seems to work. I am able to calculate the adjusted quantity but not able to get the adjusted buy…
2
votes
2 answers

How can I calculate Weighted Average on google sheets based on a condition?

I wanted to find out a non zero weighted average from 2 arrays in google sheets - the weighted average/sumproduct should be calculated only when value in column A is not zero. I cannot change or remove data - only a formula can solve…
2
votes
1 answer

Normalizing workouts based on activity, total milage, and total time

My friends and I are competing in our own fitness challenge (Sober October) where we are keeping track of Activity, Total Time Spent Moving, and Distance. Our activities include running (outdoors), running (treadmill), running (elliptical), rowing,…
BlondeSwan
  • 772
  • 5
  • 26
2
votes
1 answer

Howe to calculate the weighted average price having multiple categories and subcategories?

I want to calculated the weighted average price in SQL for each level i.e. L0,L1, and L2. Currently, I only know the formula for calculating the general weighted avg = sum(price*units)/sum(units). SELECT COALESCE((price*units)/units, 0) AS…
Cooper
  • 131
  • 1
  • 9
2
votes
2 answers

Vectorize weighted mean by list of names in each row of a data.frame

I have two dataframes. I would like to calculate a weighted mean for each row of my results dataframe from the values in my values dataframe. Each row of results has two columns with lists. Every possible combination of the lists is a row in the…
esperluette
  • 1,792
  • 2
  • 14
  • 21
2
votes
2 answers

How to add a weighted average summary to a DevExpress XtraGrid?

The DevExpress Grid (XtraGrid) allows grids and their groups to have summary calculations. The available options are Count, Max, Min, Avg, Sum, None and Custom. Has anyone got some sample code that shows how to calculate a weighted average column,…
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
2
votes
2 answers

How to compute weighted average of tensor A along an axis with weights specified by tensor B in tensorflow?

I am trying to apply a weighted average scheme on RNN output. RNN output is represented by tensor A having dimension (a,b,c). I can simply take tf.reduce_mean(A,axis=1) to get the tensor C having dimension (a,c). However, I want to do the…
2
votes
1 answer

Calculate the weighted average with JavaScript from a 2d array

I am trying to calculate the weighted average from a 2d javascript array. This is the array: var timestamp = [ [1524751200, 6000], [1556287200, 6000], [1587909600, 6000], [1619445600, 6000], [1650981600, 3000], [1682517600, 3000], …
GeorgeS
  • 107
  • 9
2
votes
3 answers

How do I calculate a weighted moving average with custom weights?

I'm working with NHL player performance data, and have a data frame with the following variables (among others). war_82 is a measure of player value over a full 82 game season. The data spans 11 seasons, from 2007-2008 to 2017-2018. first_name…
Luke Steer
  • 107
  • 1
  • 8