aggregate

django-filter and aggregate functions

北战南征 提交于 2019-12-10 18:24:20
问题 This is an app specific question: django-filter, here is a brief explanation for those who have not used it. f = ProductFilter(request.GET, queryset=Product.objects.all()) This line does all the filtering for us. ProductFilter is a class, we have specified with filters (forms-alike class). f is a filter object (basically items we have asked for), which acts similar to a list. Now, I'd like to perform aggregate functions (like Avg for instance) on this f object. Do you have any ideas how/if

How to groupby two fields in pandas?

限于喜欢 提交于 2019-12-10 18:03:46
问题 Given following input, the goal is to group values by hour for each Date with Avg and Sum functions. Solution to grouping it by hour is here, but it does not consider new days. Date Time F1 F2 F3 21-01-16 8:11 5 2 4 21-01-16 9:25 9 8 2 21-01-16 9:39 7 3 2 21-01-16 9:53 6 5 1 21-01-16 10:07 4 6 7 21-01-16 10:21 7 3 1 21-01-16 10:35 5 6 7 21-01-16 11:49 1 2 1 21-01-16 12:03 3 3 1 22-01-16 9:45 6 5 1 22-01-16 9:20 4 6 7 22-01-16 12:10 7 3 1 Expected output: Date,Time,SUM F1,SUM F2,SUM F3,AVG F1

Pandas aggregate — how to retain all columns

不羁岁月 提交于 2019-12-10 17:09:01
问题 Example dataframe: rand = np.random.RandomState(1) df = pd.DataFrame({'A': ['group1', 'group2', 'group3'] * 2, 'B': rand.rand(6), 'C': rand.rand(6), 'D': rand.rand(6)}) print df A B C D 0 group1 0.417022 0.186260 0.204452 1 group2 0.720324 0.345561 0.878117 2 group3 0.000114 0.396767 0.027388 3 group1 0.302333 0.538817 0.670468 4 group2 0.146756 0.419195 0.417305 5 group3 0.092339 0.685220 0.558690 Groupby column A group = df.groupby('A') Use agg to return max value for each group max1 =

Does Asp.net Web API 2.2 OData4 support group by clause?

核能气质少年 提交于 2019-12-10 16:51:34
问题 Does Asp.net Web API 2.2 OData4 support aggregates and groupby clause? I could not find any conclusive answer to this . 回答1: An alternative is to implement your service using the QueryByCube linq extension method provided by the AdaptiveLINQ component. For example: [EnableQuery] public IQueryable<SalesCubeItem> Get() { return DataContext.OrderDetails.QueryByCube(new SalesCubeDefinition()); } where SalesCubeDefinition define: 2 dimensions: ProductName and CustomerName 2 measures: Sales ,

Aggregate data by equally spaced time intervals in R

时间秒杀一切 提交于 2019-12-10 16:06:38
问题 My dataset is something like this Section Time x s3 9:35 2 s4 9:35 2 s1 9:36 1 s2 10:01 1 s8 11:00 2 So, I want to group the data section wise on hourly interval and sum up the x values that lies in that interval My expected output is sec Time x s1 9:00-10:00 1 s2 9:00-10:00 0 s3 9:00-10:00 2 s4 9:00-10:00 2 s8 9:00-10:00 0 s1 10.00-11.00 0 s2 10.00-11.00 1 s3 10.00-11.00 0 s4 10.00-11.00 0 s8 10.00-11.00 1 I tried to get some help from this post in stack overflow, but I am getting the

Pandas MultiIndex DataFrame.rolling offset

核能气质少年 提交于 2019-12-10 14:54:33
问题 Why can't I use an offset when rolling a multi-index DataFrame? For example, with: rng = pd.date_range('2017-01-03', periods=20, freq='8D') i = pd.MultiIndex.from_product([['A','B','C'], rng], names=['Name','Date']) df = pd.DataFrame(np.random.randn(60), i, columns=['Vals']) If I try grouping and rolling with an offset I get " ValueError: window must be an integer ": df['Avg'] = df.groupby(['Name'])['Vals'].rolling('30D').mean() # << Why doesn't this work? Not that these following variants

How to use aggregate with a list of column names

Deadly 提交于 2019-12-10 14:07:36
问题 How do you abstract aggregate in a function by passing a list of conditions and values to summarize? # This works fine: x <- data.frame(cond1 = sample(letters[1:3], 500, replace=TRUE), cond2 = sample(LETTERS[1:7], 500, replace = TRUE), cond3 = sample(LETTERS[1:4], 500, replace = TRUE), value1 = rnorm(500), value2 = rnorm(500)) aggregate(cbind(value1,value2) ~ cond1 + cond2, data = x, FUN=sum) Need to create a list of column names: (3 options shown) then call the function: c1 <- c("cond1",

OrientDB group by query using graph

ε祈祈猫儿з 提交于 2019-12-10 11:40:29
问题 I need to perform an grouped aggregate on a property of vertices of a certain class, the group by field is however a vertex two steps away from my current node and I can't make it work. My case : The vertex A contains the property I want to aggregate on and have n number of vertices with label references . The vertex I want to group on is any of those vertices (B, C or D) if that vertex has a defined by edge to vertex F . A ----references--> B --defined by--> E \---references--> C --defined

Python - Aggregate by month and calculate average

为君一笑 提交于 2019-12-10 10:42:02
问题 I have a csv which looks like this: Date,Sentiment 2014-01-03,0.4 2014-01-04,-0.03 2014-01-09,0.0 2014-01-10,0.07 2014-01-12,0.0 2014-02-24,0.0 2014-02-25,0.0 2014-02-25,0.0 2014-02-26,0.0 2014-02-28,0.0 2014-03-01,0.1 2014-03-02,-0.5 2014-03-03,0.0 2014-03-08,-0.06 2014-03-11,-0.13 2014-03-22,0.0 2014-03-23,0.33 2014-03-23,0.3 2014-03-25,-0.14 2014-03-28,-0.25 etc And my goal is to aggregate date by months and calculate average of months. Dates might not start with 1. or January. Problem is

Aggregating rows with same Ids and retaining only unique entries in R

隐身守侯 提交于 2019-12-10 10:37:17
问题 I am a beginner in R. I have data frame in R as follows: Id Values A_0_d Low_5524; Low_6412; Hi_50567 A_0_d Low_5509; Low_6412; Low_6897; Hi_16021 A_0_d Low_5524; Low_4930; Low_5886 B_1_d Low_3697; Low_4519; Low_5524 C_3_d Low_5576; Low_5581 C_3_d Hi_30246 C_3_d Low_5576; Hi_30246 I would like aggregate the data frame based on the Ids i.e. group all the values of same ID in a single row and retain only unique entries like follows: A_0_d Low_5524; Low_6412; Hi_50567; Low_5509; Low_6897; Hi