aggregate

Using result of aggregate from top level group inside lower level group

萝らか妹 提交于 2019-12-24 11:40:18
问题 I have 2 tables A{int id,int grp}, B{int aid,int cat}. Table B contains list of categories that record of table A belongs to, so B.aid is Foreign Key that references A.id. A.id is unique primary key of table A. B.cat contains category number from 1 to 5, A.grp contains numbers from 1 to 1000. Table A has 3 million of records, table B - about 5 million. For each group A.grp I need to calculate % of records in A that contain B.cat out of number of records within group A.grp. So if A:[{1,1},{2,1

Aggregation and extra values with Django

家住魔仙堡 提交于 2019-12-24 09:18:04
问题 I have a model which looks like this: class MyModel(models.Model) value = models.DecimalField() date = models.DatetimeField() I'm doing this request: MyModel.objects.aggregate(Min("value")) and I'm getting the expected result: {"mymodel__min": the_actual_minimum_value} However, I can't figure out a way to get at the same time the minimum value AND the associated date (the date at which the minimum value occured). Does the Django ORM allow this, or do I have to use raw SQL ? 回答1: What you want

SQL query minimum maximum

自古美人都是妖i 提交于 2019-12-24 07:50:04
问题 I need to get maximum and minimum values but also I need to get row id of these maximum or minimum on the same row. SELECT MIN([Value]), MAX([Value]), id FROM [AnalystEstimates].[dbo].[AnalystEstimateValues] GROUP BY indicatorid 回答1: It's very unclear what you want from your question. Do you really want the GROUP BY indicatorid? If not then it's quite simple and you already have many answers. But if you do want to GROUP BY then it's more difficult and no-one has got it quite right yet. I also

How to set 'cursor' option in Aggregate MongoDB

大兔子大兔子 提交于 2019-12-24 07:18:48
问题 I have an Aggregate command on my API Server. It worked well until I updated my MongoDB to 3.6.3. Now I get this kind of error:"The 'cursor' option is required, except for aggregate with the explain argument". This is my example: ArchiveReq.aggregate({ $project: { projectId: 1, projectName: 1, shortDescription: 1, numOfStudents: 1, creationDate: 1, matches: {$ne: ['$creationDate', '$updateDate']} } }, function (err, Requests) { if (err) return res.send(err) res.json(Requests); } ); 回答1:

MongoDB aggregate return count of 0 if no documents

六月ゝ 毕业季﹏ 提交于 2019-12-24 07:08:11
问题 I have a MongoDB query that groups by 5min windows based on date and returns count (which is the total number of documents in that 5min window using count: { $sum: 1 } ). I'd like to have the query also return a count of 0 for a particular 5min window if no documents exist in that group. However currently, looks like only groups with a positive count are returned. Current Query: const cursor = await collection.aggregate([ { $sort : { time : 1 } }, { $match: { $and: [ {selector: string },

How to aggregate every 30 minutes in R

自作多情 提交于 2019-12-24 06:03:05
问题 I am stuck in R. I need to aggregate every minute data into every 30 minutes. My data frame is like this: Date Time Power 2008-10-11 23:57:00 0.376 2008-10-11 23:58:00 0.374 2008-10-11 23:59:00 0.374 2008-10-12 0:00:00 0.334 2008-10-12 0:01:00 0.330 ... 2008-12-13 19:24:00 1.390 2008-12-13 19:25:00 1.370 2008-12-13 19:26:00 1.368 2008-12-13 19:27:00 1.362 2008-12-13 19:28:00 1.352 2008-12-13 19:29:00 1.360 ... Basically, I have 500,979 rows of data for 2008. Every minute gives a power value.

How to aggregate every 30 minutes in R

旧巷老猫 提交于 2019-12-24 06:02:34
问题 I am stuck in R. I need to aggregate every minute data into every 30 minutes. My data frame is like this: Date Time Power 2008-10-11 23:57:00 0.376 2008-10-11 23:58:00 0.374 2008-10-11 23:59:00 0.374 2008-10-12 0:00:00 0.334 2008-10-12 0:01:00 0.330 ... 2008-12-13 19:24:00 1.390 2008-12-13 19:25:00 1.370 2008-12-13 19:26:00 1.368 2008-12-13 19:27:00 1.362 2008-12-13 19:28:00 1.352 2008-12-13 19:29:00 1.360 ... Basically, I have 500,979 rows of data for 2008. Every minute gives a power value.

Best way to aggregate a list of items and collect totals

那年仲夏 提交于 2019-12-24 03:59:11
问题 I'm wondering if there's a good fold (or map, reduce etc.) style solution to this problem. Give a collection of purchases (order_items) I want to gather the totals for each product/sku. Example collection: [{sku: "A", price:10}, {sku: "B", price:5}, {sku: "C", price:2}, {sku: "B", price:5}, {sku: "A", price:10}, {sku: "B", price:5}] And get a result of: {"A":20, "B":15, "C":2} At present I do it like so: aggregate = order_items.each_with_object({}){|i,o| o[i[:sku]] ||= 0 o[i[:sku]] += i[

How to combine ';'.join and lambda x: x.tolist() inside an groupby.agg() function?

僤鯓⒐⒋嵵緔 提交于 2019-12-24 03:51:34
问题 Update down below! I am trying to merge and sort a list of IDs and their connected unique Name_ID, separated by semicolons. For example: Name_ID Adress_ID Name_ID Adress_ID Name1 5875383 Name1 5875383; 5901847 Name1 5901847 Name2 5285200 Name2 5285200 to Name3 2342345; 6463736 Name3 2342345 Name3 6463736 This is my current code: origin_file_path = Path("Folder/table.xlsx") dest_file_path = Path("Folder/table_sorted.xlsx") table = pd.read_excel(origin_file_path) df1 = pd.DataFrame(table) df1 =

How to combine ';'.join and lambda x: x.tolist() inside an groupby.agg() function?

我们两清 提交于 2019-12-24 03:51:05
问题 Update down below! I am trying to merge and sort a list of IDs and their connected unique Name_ID, separated by semicolons. For example: Name_ID Adress_ID Name_ID Adress_ID Name1 5875383 Name1 5875383; 5901847 Name1 5901847 Name2 5285200 Name2 5285200 to Name3 2342345; 6463736 Name3 2342345 Name3 6463736 This is my current code: origin_file_path = Path("Folder/table.xlsx") dest_file_path = Path("Folder/table_sorted.xlsx") table = pd.read_excel(origin_file_path) df1 = pd.DataFrame(table) df1 =