aggregate

How do I conditionally aggregate values in projection part of pandas query?

这一生的挚爱 提交于 2019-12-11 05:23:42
问题 I currently have a csv file with this content: ID PRODUCT_ID NAME STOCK SELL_COUNT DELIVERED_BY 1 P1 PRODUCT_P1 12 15 UPS 2 P2 PRODUCT_P2 4 3 DHL 3 P3 PRODUCT_P3 120 22 DHL 4 P1 PRODUCT_P1 423 18 UPS 5 P2 PRODUCT_P2 0 5 GLS 6 P3 PRODUCT_P3 53 10 DHL 7 P4 PRODUCT_P4 22 0 UPS 8 P1 PRODUCT_P1 94 56 GLS 9 P1 PRODUCT_P1 9 24 GLS When I execute this SQL query: SELECT PRODUCT_ID, MIN(CASE WHEN DELIVERED_BY = 'UPS' THEN STOCK END) as STOCK, SUM(CASE WHEN ID > 6 THEN SELL_COUNT END) as TOTAL_SELL

What's the fastest way to obtain the maximum value of a column in a table?

偶尔善良 提交于 2019-12-11 05:01:38
问题 INFORMIX-SQL 4.10.DC1 (SE Engine), on DOS 6.22, under Microsoft Virtual PC 2007, in Windows 7! EDIT: Looking for Jonathan Leffler's wisdom on this one! I have a child table called transaction and a parent table called customer. These tables are joined by customer.pk_id SERIAL = transaction.fk_id INTEGER. The transaction table has a clustered index on fk_id so that each customers transactions are physically grouped together with the data matching the index. The reason I chose the cluster index

Pandas Grouping - Values as Percent of Grouped Totals Based on Another Column

喜欢而已 提交于 2019-12-11 04:53:52
问题 This question is an extension of a question I asked yesterday, but I will rephrase Using a data frame and pandas, I am trying to figure out what the tip percentage is for each category in a group by. So, using the tips database, I want to see, for each sex/smoker, what the tip percentage is is for female smoker / all female and for female non smoker / all female (and the same thing for men) When I do this, import pandas as pd df=pd.read_csv("https://raw.githubusercontent.com/wesm/pydata-book

Apache Camel multicast, exception and Aggregation strategy

元气小坏坏 提交于 2019-12-11 04:47:14
问题 I define a complex route in which I had to to orchestrate different simple operations. from(cxfCartEndpoint).routeId("receiveCart") .to("log:com.sdmo.input?level="+LOG_LEVEL) .process(cartWSExtractProcessor) .to(loggingMesssagesPath+"?fileName=originalRequest${date:now:yyyyMMdd-HHmmss}.xml") .multicast(aggregationStrategy).stopOnException() .to("mock:doNothing","direct:copyItem","direct:XmlSave","direct:manageFinalResponse") .end() .to(loggingMesssagesPath+"?fileName=finalResponse${date:now

Max within a timeframe with date duplicates

北城余情 提交于 2019-12-11 04:43:55
问题 I have a table like this DateTime start_time not null, DateTime end_time not null, Status_Id int not null, Entry_Id int not null I want to get the count of each status within a time period, where only the last started is valid for a given entry_id. What I am using now is this (with dynamic dates): with c (Status_Id, Entry_Id, Start_Date) AS ( select Status_Id, Entry_Id, Start_Date from tbl where (End_Date BETWEEN '19000101' AND '21000101') AND ((Start_Date BETWEEN '19000101' AND '21000101')

Python: Summarizing & Aggregating Groups and Sub-groups in DataFrame

蹲街弑〆低调 提交于 2019-12-11 04:21:17
问题 I am trying to build a table that has groups that are divided by subgroups with count and average for each subgroup. For example, I want to convert the following data frame: To a table that looks like this where the interval is a bigger group and columns a thru i become subgroups within the group with the corresponding subgroups' count and average in each cell: I have tried this with no success: 回答1: Use DataFrame.melt with GroupBy.agg and tuples for aggregate functions with new columns names

Does aggregate() guarantee that the result will be ordered by the grouping columns?

穿精又带淫゛_ 提交于 2019-12-11 03:57:15
问题 I've noticed that aggregate() appears to return its result ordered by the grouping column(s). Is this a guarantee? Can this be relied upon in surrounding logic? A couple of examples: set.seed(1); df <- data.frame(group=sample(letters[1:3],10,replace=T),value=1:10); aggregate(value~group,df,sum); ## group value ## 1 a 16 ## 2 b 22 ## 3 c 17 And with two groups (notice the second group is ordered first, then the first group to break ties): set.seed(1); df <- data.frame(group1=sample(letters[1:3

Dynamic Grouping in R | Grouping based on condition on applied function

那年仲夏 提交于 2019-12-11 03:53:29
问题 In R, in aggregate() function, How to specify stopping condition on grouping on applied function on the variable? For example, I have data-frame like this: "df" Input Data frame Note : Assuming each row in input data frame is denoting single ball played by a player in that match. So, by counting a number of rows can tell us the number of balls required. And, I want my data frame like this one: Output data frame My need is: How many balls are required to score 10 runs? Currently, I am using

aggregate returns empty array - mongoose

跟風遠走 提交于 2019-12-11 03:25:56
问题 I have the following two simple queries: Comment.aggregate([{$match: { _id: req.params.id }}]) .exec(function(err, result) { // result is empty }); Comment.find({ _id: req.params.id }) .exec(function (err, result) { // correct result returned }); My problem is, that the aggregate-Function returns an empty array. Aren't they supposed to return the same result? 回答1: Yes, but you need to cast the id (which is a string) to an objectID :) let idToSearch = mongoose.Types.ObjectId(req.params.id)

summarize values on a tree

偶尔善良 提交于 2019-12-11 03:17:40
问题 I used a Tree control to view some hierarchical items base on a nested (parent child) table . Every node has a NameValue format that accept either a name and value . But only Leaves (last nodes) have integer values and values of parents are left blank (just the Names they have) . I want to summarize values so that every parent hold the sum of it's sub nodes and leaves values . I think recursion or maybe LINQ is needed to accomplish this task but i don't know how ? maybe some pseudo code will