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
1
vote
0 answers

DAX: Weighted Average on Different Level of Aggregation using Netted Summarized Table

I have the following test Data set, with 3 different levels of grouping. And I want to make a measure "Value WA" for Value, and the make a matrix like showing in the image after. Basically, it is the weighted average of "Value" based on "Market…
Alex
  • 11
  • 3
1
vote
1 answer

Weighted Mean row wise Pandas

I would like to compute the weighted mean for each row, for a given weight 'wt': df = pd.DataFrame( { 'datetime': ['2015-01-02', '2015-01-03', '2015-01-04', '2015-01-05', '2015-01-06'], 'var1': [0, 0, 1, 1, 1], 'var2': [-1, -2, 1, 2,…
Niccola Tartaglia
  • 1,537
  • 2
  • 26
  • 40
1
vote
1 answer

Multiple Group - Weighted mean - not working in r (using dplyr)

I am trying to obtain the weighted mean of some soil properties, weighted by their surface but aggregated by their owner and other levels. My dataset looks like this full_dataset and i would like to obtain the mean like thismean_dataset. My code…
1
vote
1 answer

How to calculate cumulative weighted average using pandas

I would like to ask you about how to find the cumulative average of a specific column value in a pandas dataframe. First, the data looks like…
1
vote
2 answers

How to calculate time weighted average using Python?

So i have data with irregular intervals in a day. Event Time Value 17-5-2021 03:00 84.9 17-5-2021 11:00 84.9 17-5-2021 15:00 84.7 17-5-2021 23:00 84.7 18-5-2021 03:00 84.5 18-5-2021 11:00 84.5 18-5-2021 15:00 84.9 18-5-2021…
1
vote
2 answers

How do you apply 2 or more functions on the right side of `dplyr::across` in R to find weighted.means and variances?

I am trying to use dplyr::across to find the weighted centroid and variance for Latitude and Longitude for each "Early" and "Late" Periods. My data looks something like this: dat <- data.frame(Latitude = c(35.8, 35.85, 36.7, 35.2, 36.1, 35.859,…
Nick Masto
  • 125
  • 8
1
vote
1 answer

Google sheets weighted average function: How do I set this to only use non-zero values?

I'm new to Google sheets / excel and I'm a bit lost. Column E is found by D/C. How do I find the weighted average (B6), but only for values in the E column that have not been filled in yet? I tried <>"" but it showed an error.
1
vote
1 answer

weighted.mean inside aggregate across 2 vectors in R?

I have a dataframe with vectors Latitude, Longitude, Period, and ID. I would like to calculate the positional centroid for each period (n = 2), weighted by the number of observations for each unique ID, so that IDs with fewer observations receive…
Nick Masto
  • 125
  • 8
1
vote
1 answer

Weighted average grouping by date (in index) in pandas DataFrame

I need some help trying to obtain a weighted average for a column, based on datetime-index and another 'mass' column. For example: d = {'date': ['2021-08-01 12:00:00', '2021-08-01 13:00:00', '2021-08-01 14:00:00', '2021-08-02 15:00:00', '2021-08-02…
Elias Urra
  • 83
  • 1
  • 11
1
vote
2 answers

weighted average aggregation on multiple columns of df

I'm trying to calculate a weighted average for multiple columns in a dataframe. This is a sample of my…
brenda89
  • 99
  • 9
1
vote
1 answer

Calculate the weighted average using groupby in Python

here is the dataframe I'm currently working on : df_weight_0 What I'd like to calculate is the average of the variable "avg_lag" weighted by "tot_SKU" in each product_basket for both SMB and CORP groups. This means that, taking CORP as an example,…
1
vote
3 answers

Weighted Mean as a Column in Pandas

I am trying to add a column with the weighted average of 4 columns with 4 columns of weights df = pd.DataFrame.from_dict(dict([('A', [2000, 1000, 2509, 2145]), ('A_Weight', [37, 47, 33, 16]), …
1
vote
1 answer

Weighted average grouping by date (in index) in pandas DataFrame (different operations per column)

I have a dataframe with several rows per day, a 'mass' column and a '%' value that needs to be ponderated as a weighted average depending on the mass; and the mass column a sum... creating a new dataframe with all values. d = {'date': [1, 1, 1, 2,…
Elias Urra
  • 83
  • 1
  • 11
1
vote
0 answers

Weighted mean, sd and median - Size Weighted (Negative Numbers)

I need to calculate the weighted median, average, sd of PE funds' returns. I weighted the sample according to the amount of committed capital of a fund, but I should consider negative products to analyze underperforming funds. However, I'm not sure…
VikTrim
  • 11
  • 1
1
vote
0 answers

How to attach CI on dot graphs for weighted means (y-axis) at multiple factor levels (x-axis) in R?

I have the following data frame; here a sample of it. One factor year, four integer variables ep1:ep4 and one weighting variable w. I use R v.4.0.2 and Rstudio v.1.2.5042. I want to have the weighted means calculated for each year separately and…