weighted-average

Use numpy.average with weights for resampling a pandas array

℡╲_俬逩灬. 提交于 2020-01-05 09:36:27
问题 I need to resample some data with numpys weighted-average-function - and it just doesn't work... . This is my test-case: import numpy as np import pandas as pd time_vec = [datetime.datetime(2007,1,1,0,0) ,datetime.datetime(2007,1,1,0,1) ,datetime.datetime(2007,1,1,0,5) ,datetime.datetime(2007,1,1,0,8) ,datetime.datetime(2007,1,1,0,10) ] df = pd.DataFrame([2,3,1,7,4],index = time_vec) A normal resampling without weights works fine (using the lambda function as a parameter to how is suggested

DAX - 2 phased weighted average with 2 different weight measures

那年仲夏 提交于 2020-01-05 05:31:07
问题 I have rather complex problem to expres. In DAX powerpivot I am trying to create measure which will be using two different Weighted averages in one measure based on aggregation level. The problem is complicated even more, because weight measures have different level of duplication (need to apply distinct SUM on them).I have been able to create Distinct SUM Measure1 and 2 to solve that. [Weight_1] = SUMX(DISTINCT(Table1[Level2],[SupportWeight1]) [SupportWeight1] = MAX(Table1[RevenueLevel2])

Aggregate and Weighted Mean for multiple columns in R

断了今生、忘了曾经 提交于 2020-01-04 06:50:33
问题 The question is basically the samt as this: Aggregate and Weighted Mean in R. But i want it to compute it on several columns, using data.table, as I have millions of rows. So something like this: set.seed(42) # fix seed so that you get the same results dat <- data.frame(assetclass=sample(LETTERS[1:5], 20, replace=TRUE), tax=rnorm(20),tax2=rnorm(20), assets=1e7+1e7*runif(20), assets2=1e6+1e7*runif(20)) DT <- data.table(dat) I can compute the weighted mean on one column, assets, like this: DT[

Joining data with weighted averages and multiple weights in R

此生再无相见时 提交于 2020-01-02 12:40:41
问题 So I had this question but the scope got a little larger/more complicated. Basically I want to combine two tables and calculate the weighted average for any duplicate IDs. The problem is I will have multiple sets of columns that will need to use different weights. Here's my two datasets (RMS1 and RMS2) and the desired outcome (Joined): RMS1: id,freq1,sev1,count1,freq2,sev2,count2 111 0 2 50 1 2 25 222 1 3 75 2 4 50 RMS2: id,freq1,sev1,count1,freq2,sev2,count2 222 2 4 25 6 6 200 333 4 5 60 3 2

Joining data with weighted averages and multiple weights in R

狂风中的少年 提交于 2020-01-02 12:40:40
问题 So I had this question but the scope got a little larger/more complicated. Basically I want to combine two tables and calculate the weighted average for any duplicate IDs. The problem is I will have multiple sets of columns that will need to use different weights. Here's my two datasets (RMS1 and RMS2) and the desired outcome (Joined): RMS1: id,freq1,sev1,count1,freq2,sev2,count2 111 0 2 50 1 2 25 222 1 3 75 2 4 50 RMS2: id,freq1,sev1,count1,freq2,sev2,count2 222 2 4 25 6 6 200 333 4 5 60 3 2

How to calculate iteratively the running weighted average so that last values to weight most?

南楼画角 提交于 2020-01-01 08:28:00
问题 I want to implement an iterative algorithm, which calculates weighted average. The specific weight law does not matter, but it should be close to 1 for the newest values and close to 0 to the oldest. The algorithm should be iterative. i.e. it should not remember all previous values. It should know only one newest value and any aggregative information about past, like previous values of the average, sums, counts etc. Is it possible? For example, the following algorithm can be: void iterate

bootstrap samples by row of a data frame in r

懵懂的女人 提交于 2019-12-25 04:24:11
问题 I am trying to run a simple bootstrap on the rows of a data frame in r. Here is what I have worked up so far, but I'm hitting a dead end. x1 <- c(1:5) x2 <- c(6:10) y <- runif(5) z <- as.data.frame(rbind(x1, x2, y)) trial <- 10 avg <- rep(0, trial) for(i in 1:trial){ ind <- sample(ncol(z), size = ncol(z), replace = TRUE) z.boot <- z[ind, ] mean[i] <- mean(z.boot) } mean Ideally, what I would like to do is to get a bootstrap weighted mean for the first and second rows with the weights in the

Getting a weighted average in R when joining two tables

雨燕双飞 提交于 2019-12-24 19:07:45
问题 I'm just going to apologize in advance for anything confusing and/or dumb about this question. I am completely new to R but because of larger project restrictions, I am currently forced to use it for this task. Right now I have two tables that I would like to join, RMS1 and RMS2. RMS1 is larger, and I only want to carry over matching columns from RMS2 (left join). For the most part, RMS1 and RMS2 are separate data sets with a unique ID for every entry, but there are a few overlapping IDs

Is there a way to get Pandas ewm to function on fixed windows?

↘锁芯ラ 提交于 2019-12-24 07:45:20
问题 I am trying to use Pandas ewm function to calculating exponentially weighted moving averages. However i've noticed that information seems to carry through your entire time series. What this means is that every data point's MA is dependant on a different number of previous data points. Therefore the ewm function at every data point is mathematically different. I think some here had a similar question Does Pandas calculate ewm wrong? But i did try their method, and i am not getting

Pandas: filling missing values by weighted average in each group

别说谁变了你拦得住时间么 提交于 2019-12-23 22:19:25
问题 I have a dataFrame where 'value'column has missing values. I'd like to filling missing values by weighted average within each 'name' group. There was post on how to fill the missing values by simple average in each group but not weighted average. Thanks a lot! df = pd.DataFrame({'value': [1, np.nan, 3, 2, 3, 1, 3, np.nan, np.nan],'weight':[3,1,1,2,1,2,2,1,1], 'name': ['A','A', 'A','B','B','B', 'C','C','C']}) name value weight 0 A 1.0 3 1 A NaN 1 2 A 3.0 1 3 B 2.0 2 4 B 3.0 1 5 B 1.0 2 6 C 3.0