aggregation

Concatenating a column by a group in R

五迷三道 提交于 2019-11-29 15:42:35
Suppose I've got this employee list: Dept Date Name ----- --------- --------------- 30 07-DEC-02 Raphaely 30 18-MAY-03 Khoo 40 07-JUN-02 Mavris 50 01-MAY-03 Kaufling 50 14-JUL-03 Ladwig 70 07-JUN-02 Baer 90 13-JAN-01 De Haan 90 17-JUN-03 King 100 16-AUG-02 Faviet 100 17-AUG-02 Greenberg 110 07-JUN-02 Gietz 110 07-JUN-02 Higgins I want a list aggregation by department in R (similar to Oracle PL/SQL's LISTAGG function ) that would product this last column: Dept Date Name Emp_list ----- --------- --------------- --------------------------------------------- 30 07-DEC-02 Raphaely Raphaely; Khoo 30

Pandas: aggregate when column contains numpy arrays

跟風遠走 提交于 2019-11-29 14:52:16
问题 I'm using a pandas DataFrame in which one column contains numpy arrays. When trying to sum that column via aggregation I get an error stating 'Must produce aggregated value'. e.g. import pandas as pd import numpy as np DF = pd.DataFrame([[1,np.array([10,20,30])], [1,np.array([40,50,60])], [2,np.array([20,30,40])],], columns=['category','arraydata']) This works the way I would expect it to: DF.groupby('category').agg(sum) output: arraydata category 1 [50 70 90] 2 [20 30 40] However, since my

When object A instantiates/aggrgate/acquaint object B, must object A have a field member referencing object B?

我只是一个虾纸丫 提交于 2019-11-29 13:08:47
From Design Pattern by GoF: An object reference representing a part-of or aggregation relationship is indicated by an arrowheaded line with a diamond at the base. The arrow points to the class that is aggregated (e.g., Shape). An arrowheaded line without the diamond denotes acquaintance (e.g., a LineShape keeps a reference to a Color object, which other shapes may share). A name for the reference may appear near the base to distinguish it from other references Another useful thing to show is which classes instantiate which others. We use a dashed arrowheaded line to indicate this, since OMT

Add RawContact so it aggregates to an existing contact

房东的猫 提交于 2019-11-29 12:43:26
问题 I am trying to add a new RawContact to an existing Contact so my custom data field shows up inside the original Contact. I tried Adding a StructuredName Data row to my new RawContact with a DisplayName that matches the DisplayName of the original RawContact. I thought matching DisplayNames would be enough to aggregate both RawContacts but the contacts app seems to display both RawContacts as different Contacts. Here is my code public static void addContact(Context context, Account account,

SQL Server pick random (or first) value with aggregation

一个人想着一个人 提交于 2019-11-29 11:46:06
How can I get SQL Server to return the first value (any one, I don't care, it just needs to be fast) it comes across when aggregating? For example, let's say I have: ID Group 1 A 2 A 3 A 4 B 5 B and I need to get any one of the ID's for each group. I can do this as follows: Select max(id) ,group from Table group by group which returns ID Group 3 A 5 B That does the job, but it seems stupid to me to ask SQL Server to calculate the highest ID when all it really needs to do is to pick the first ID it comes across. Thanks PS - the fields are indexed, so maybe it doesn't really make a difference?

How can I vectorize the averaging of 2x2 sub-arrays of numpy array?

北城以北 提交于 2019-11-29 10:57:19
I have a very a very large 2D numpy array that contains 2x2 subsets that I need to take the average of. I am looking for a way to vectorize this operation. For example, given x: # |- col 0 -| |- col 1 -| |- col 2 -| x = np.array( [[ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0], # row 0 [ 6.0, 7.0, 8.0, 9.0, 10.0, 11.0], # row 0 [12.0, 13.0, 14.0, 15.0, 16.0, 17.0], # row 1 [18.0, 19.0, 20.0, 21.0, 22.0, 23.0]]) # row 1 I need to end up with a 2x3 array which are the averages of each 2x2 sub array, i.e.: result = np.array( [[ 3.5, 5.5, 7.5], [15.5, 17.5, 19.5]]) so element [0,0] is calculated as the average

Sorting after aggregation in Elasticsearch

旧时模样 提交于 2019-11-29 02:53:20
问题 I have docs with this structure: { FIELD1:string, FIELD2: [ {SUBFIELD:number}, {SUBFIELD:number}...] } I want to sort on the result of the sum of numbers in FIELD2.SUBFIELDs: GET myindex/_search { "size":0, "aggs": { "a1": { "terms": { "field": "FIELD1", "size":0 }, "aggs":{ "a2":{ "sum":{ "field":"FIELD2.SUBFIELD" } } } } } } If I do this I obtain buckets not sorted, but I want buckets sorted by "a2" value. How I can do this? Thank you! 回答1: You almost had it. You just need to add an order

Django Aggreagtion: Sum return value only?

女生的网名这么多〃 提交于 2019-11-29 01:54:16
问题 I have a list of values paid and want to display the total paid. I have used Aggregation and Sum to calculate the values together. The problem is,I just want the total value printed out, but aggreagtion prints out: {'amount__sum': 480.0} (480.0 being the total value added. In my View, I have: from django.db.models import Sum total_paid = Payment.objects.all.aggregate(Sum('amount')) And to show the value on the page, I have a mako template with the following: <p><strong>Total Paid:</strong> $

Vector as a class member

走远了吗. 提交于 2019-11-29 00:42:42
Hello I have this question: I would like to have a vector as class member. This is perhaps my question easier for you and I apologize for that. how should I declare the vector? And is this correct? std::vector<int> *myVector; or std::vector<int> myVector ? how should I handle this vector in dealloc? How can I initialize the array into a if? Is this correct? if(myCondition) { if(!myVector) //is this correct? myVector = new std::vector<int>(); //is this correct? on this i have a error } You most certainly want to use std::vector<int> myVector . No need to initialize it, as it gets automatically

UML Notation - Aggregations/Compositions vs “Vanilla” Associations

我只是一个虾纸丫 提交于 2019-11-29 00:14:34
I've recently spent a good deal of time performing detailed UML designs of various SW components that I have since written. Looking back on what I have recently finished and comparing that to when I first learned UML, I see that I now almost strictly use Aggregation and Composition relationships, and have virtually abandoned "vanilla" non-directed/directed relationships. I still of course use Generalizations and Realizations, but these are distinctly different than those above and are not considered part of this question. It seems to me that Aggregation/Composition implies the same meaning of