group-by

.EACHI in data.table?

Deadly 提交于 2019-12-17 02:05:18
问题 I cannot seem to find any documentation on what exactly .EACHI does in data.table . I see a brief mention of it in the documentation: Aggregation for a subset of known groups is particularly efficient when passing those groups in i and setting by=.EACHI . When i is a data.table, DT[i,j,by=.EACHI] evaluates j for the groups of DT that each row in i joins to. We call this grouping by each i. But what does "groups" in the context of DT mean? Is a group determined by the key that is set on DT ?

.EACHI in data.table?

六月ゝ 毕业季﹏ 提交于 2019-12-17 02:05:12
问题 I cannot seem to find any documentation on what exactly .EACHI does in data.table . I see a brief mention of it in the documentation: Aggregation for a subset of known groups is particularly efficient when passing those groups in i and setting by=.EACHI . When i is a data.table, DT[i,j,by=.EACHI] evaluates j for the groups of DT that each row in i joins to. We call this grouping by each i. But what does "groups" in the context of DT mean? Is a group determined by the key that is set on DT ?

GROUP BY to combine/concat a column [duplicate]

浪尽此生 提交于 2019-12-16 22:37:16
问题 This question already has answers here : Simulating group_concat MySQL function in Microsoft SQL Server 2005? (10 answers) Concatenate one field after GROUP BY (1 answer) Closed 5 years ago . I have a table as follow: ID User Activity PageURL 1 Me act1 ab 2 Me act1 cd 3 You act2 xy 4 You act2 st I want to group by User and Activity such that I end up with something like: User Activity PageURL Me act1 ab, cd You act2 xy, st As you can see, the column PageURL is combined together separated by a

MySQL - Selecting a Column not in Group By

吃可爱长大的小学妹 提交于 2019-12-16 22:23:46
问题 I'm trying to add features to a preexisting application and I came across a MySQL view something like this: SELECT AVG(table_name.col1), AVG(table_name.col2), AVG(table_name.col3), table_name.personID, table_name.col4 FROM table_name GROUP BY table_name.personID; OK so there's a few aggregate functions. You can select personID because you're grouping by it. But it also is selecting a column that is not in an aggregate function and is not a part of the GROUP BY clause. How is this possible???

group by dates in mongodb

梦想与她 提交于 2019-12-16 22:19:29
问题 I am working on a project in which I am tracking number of clicks on a topic. I am using mongodb and I have to group number of click by date( i want to group data for 15 days). I am having data store in following format in mongodb { "_id" : ObjectId("4d663451d1e7242c4b68e000"), "date" : "Mon Dec 27 2010 18:51:22 GMT+0000 (UTC)", "topic" : "abc", "time" : "18:51:22" } { "_id" : ObjectId("4d6634514cb5cb2c4b69e000"), "date" : "Mon Dec 27 2010 18:51:23 GMT+0000 (UTC)", "topic" : "bce", "time" :

How to groupby consecutive values in pandas DataFrame

流过昼夜 提交于 2019-12-16 20:17:27
问题 I have a column in a DataFrame with values: [1, 1, -1, 1, -1, -1] How can I group them like this? [1,1] [-1] [1] [-1, -1] 回答1: You can use groupby by custom Series : df = pd.DataFrame({'a': [1, 1, -1, 1, -1, -1]}) print (df) a 0 1 1 1 2 -1 3 1 4 -1 5 -1 print ((df.a != df.a.shift()).cumsum()) 0 1 1 1 2 2 3 3 4 4 5 4 Name: a, dtype: int32 for i, g in df.groupby([(df.a != df.a.shift()).cumsum()]): print (i) print (g) print (g.a.tolist()) a 0 1 1 1 [1, 1] 2 a 2 -1 [-1] 3 a 3 1 [1] 4 a 4 -1 5 -1

GROUP BY ID range?

…衆ロ難τιáo~ 提交于 2019-12-14 04:05:43
问题 Given a data set like this; +-----+---------------------+--------+ | id | date | result | +-----+---------------------+--------+ | 121 | 2009-07-11 13:23:24 | -1 | | 122 | 2009-07-11 13:23:24 | -1 | | 123 | 2009-07-11 13:23:24 | -1 | | 124 | 2009-07-11 13:23:24 | -1 | | 125 | 2009-07-11 13:23:24 | -1 | | 126 | 2009-07-11 13:23:24 | -1 | | 127 | 2009-07-11 13:23:24 | -1 | | 128 | 2009-07-11 13:23:24 | -1 | | 129 | 2009-07-11 13:23:24 | -1 | | 130 | 2009-07-11 13:23:24 | -1 | | 131 | 2009-07-11

Grouping with partition and over in TSql

醉酒当歌 提交于 2019-12-14 04:02:58
问题 I have a simple table CREATE TABLE [dbo].[Tooling]( [Id] [int] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](50) NOT NULL, [Status] [int] NOT NULL, [DateFinished] [datetime] NULL, [Tooling] [nvarchar](50) NULL, [Updated] [datetime] NULL, ) ON [PRIMARY] with following values SET IDENTITY_INSERT [dbo].[Tooling] ON GO INSERT [dbo].[Tooling] ([Id], [Name], [Status], [DateFinished], [Tooling], [Updated]) VALUES (1, N'Large', 0, NULL, NULL, CAST(N'2015-05-05 00:00:00.000' AS DateTime)) GO INSERT [dbo].

mean of absolute value of groupby object pandas

我的梦境 提交于 2019-12-14 03:58:42
问题 I want to compute the mean of the absolute value of a grouped object. I.e. grouped = df.groupby([pd.TimeGrouper(3MS)]) dct['x'] = grouped['profit'].agg('mean') / grouped['cost'].abs().agg('mean') However, the above code results in an error. I have tried various variants of the above code but so far all result in errors. There must be a simple way to do this. Update: This is the dataframe that is grouped vi pd.TimeGrouper(3MS). I want to take the absolute value of column cost 1, and then

php mysql asc/desc order

Deadly 提交于 2019-12-14 03:48:48
问题 TABLE: **timeslot**: ---------- id_timeslot times 1 09:00 2 09:30 3 10:00 4 10:30 5 11:00 **bookslot** id id_timeslot date b_ref ------------------------------------------- 1 2 2010-02-22 001 2 3 2010-02-22 001 3 4 2010-02-22 001 4 5 2010-02-22 001 5 2 2010-02-25 002 6 3 2010-02-27 003 7 4 2010-02-27 003 8 5 2010-02-27 003 PHP $q = $mysqli->query("SELECT * FROM bookslot LEFT JOIN timeslot ON bookslot.id_timeslot = timeslot.id_timeslot WHERE bookslot.status = 1 GROUP BY bookslot.b_ref ORDER BY