group-by

Keep columns after a groupby in an empty dataframe

廉价感情. 提交于 2019-12-23 10:07:13
问题 The dataframe is an empty df after query.when groupby,raise runtime waring,then get another empty dataframe with no columns.How to keep the columns? df = pd.DataFrame(columns=["PlatformCategory","Platform","ResClassName","Amount"]) print df result: Empty DataFrame Columns: [PlatformCategory, Platform, ResClassName, Amount] Index: [] then groupby: df = df.groupby(["PlatformCategory","Platform","ResClassName"]).sum() df = df.reset_index(drop=False,inplace=True) print df result: sometimes is

Select and Group by together

纵然是瞬间 提交于 2019-12-23 10:04:25
问题 I have my query like this: Select a.abc, a.cde, a.efg, a.agh, c.dummy p.test max(b.this) sum(b.sugar) sum(b.bucket) sum(b.something) followed by some outer join and inner join. Now the problem is when in group by group by a.abc, a.cde, a.efg, a.agh, c.dummy, p.test The query works fine. But if I remove any one of them from group by it gives: SQLSTATE: 42803 Can anyone explain the cause of this error? 回答1: Generally, any column that isn't in the group by section can only be included in the

LINQ groupby statement with key

痞子三分冷 提交于 2019-12-23 09:00:24
问题 The syntax of my query is good but not the output and it's really strange. I have the following table: | AppointID | UserID | AppointSet | AppointResolved | AppointStatus | AppointmentDatetime | 1 | 1 | 3/1/2011 | 3/1/2011 | 1 | 3/15/2011 | 2 | 1 | 3/2/2011 | 3/5/2011 | 4 | 3/16/2011 | 3 | 1 | 3/2/2011 | 3/11/2011 | 2 | 3/11/2011 | 4 | 1 | 3/3/2011 | 3/7/2011 | 3 | 3/25/2011 ApponintStatus is a byte where 1 is for set, 2 is for attended, 3 is for rescheduled and 4 is for cancelled.

How to introduce Let keyword inside Linq statement with Group by

不问归期 提交于 2019-12-23 08:38:04
问题 I have the following Linq statement with 'Group by' clause and would like to know how to introduce a let or any other statement to avoid repeating the sub query, lifecycleEvents.Where(i => i.LifecycleEventId == grouping.Key).First() in the following example var completionTimeModels = from timeline in processTimelines group timeline by timeline.LifecycleEventId into grouping select new CompletionTimeViewModel() { // How to avoid repeating the same query to find the life cycle event? Name =

SQL Querying for Threaded Messages

依然范特西╮ 提交于 2019-12-23 05:42:50
问题 My site has a messaging feature where one user may message another. The messages support threading - a parent message may have any number of children but only one level deep. The messages table looks like this: Messages - Id (PK, Auto-increment int) - UserId (FK, Users.Id) - FromUserId (FK, Users.Id) - ParentMessageId (FK to Messages.Id) - MessageText (varchar 200) I'd like to show messages on a page with each 'parent' message followed by a collapsed view of the children messages. Can I use

SQL Querying for Threaded Messages

左心房为你撑大大i 提交于 2019-12-23 05:41:09
问题 My site has a messaging feature where one user may message another. The messages support threading - a parent message may have any number of children but only one level deep. The messages table looks like this: Messages - Id (PK, Auto-increment int) - UserId (FK, Users.Id) - FromUserId (FK, Users.Id) - ParentMessageId (FK to Messages.Id) - MessageText (varchar 200) I'd like to show messages on a page with each 'parent' message followed by a collapsed view of the children messages. Can I use

Is it possible to do applymap using the groupby in pandas?

不羁岁月 提交于 2019-12-23 05:37:20
问题 In a pandas Dataframe I want to applymap(somefunction) using groupby (using some column index values). mcve_01.txt pos index M1 M2 F1_x 16230484 141 G/G G/G G 16230491 141 C/C C/C C 16230503 141 T/T T/T T 16230524 141 T/T T/T T 16230535 141 . . T 16232072 211 A/A A/A A 16232072 211 A/A A/A A 16229783 211 C/C C/C G 16229992 211 A/A A/A G 16230007 211 T/T T/T A 16230011 263 G/G G/G C 16230049 263 A/A A/A T 16230174 263 . . T 16230190 263 A/A A/A T 16230260 263 A/A A/A G I have function written

Implement aggregation in Teradata

爱⌒轻易说出口 提交于 2019-12-23 04:41:33
问题 I want to aggregate 2 fields proct_dt, dw_job_id in ascendinng order My scenario would be clear by using below queries and result. First query :- sel * from scratch.COGIPF_RUNREPORT_test1 order by proct_dt,dw_job_id where dw_job_id =10309 Output :- dw_job_id proct_dt start_ts end_ts time_diff 1 10,309 2018-03-06 00:00:00 2018-03-06 07:04:18 2018-03-06 07:04:22.457000 0 2 10,309 2018-03-06 00:00:00 2018-03-06 06:58:50 2018-03-06 06:58:51.029000 0 3 10,309 2018-03-07 00:00:00 2018-03-07 06:35

Implement aggregation in Teradata

拥有回忆 提交于 2019-12-23 04:41:08
问题 I want to aggregate 2 fields proct_dt, dw_job_id in ascendinng order My scenario would be clear by using below queries and result. First query :- sel * from scratch.COGIPF_RUNREPORT_test1 order by proct_dt,dw_job_id where dw_job_id =10309 Output :- dw_job_id proct_dt start_ts end_ts time_diff 1 10,309 2018-03-06 00:00:00 2018-03-06 07:04:18 2018-03-06 07:04:22.457000 0 2 10,309 2018-03-06 00:00:00 2018-03-06 06:58:50 2018-03-06 06:58:51.029000 0 3 10,309 2018-03-07 00:00:00 2018-03-07 06:35

How can I group by specific timestamp intervals in C# using LINQ?

大城市里の小女人 提交于 2019-12-23 04:35:21
问题 I have a list with tick objects including a pair of a double value and a timestamp. I want to separate the list into child-lists depending on a time interval (for example 15 minutes). One list only has the tick objects from: 8:00:00 - 8:14-59 usw usw C#-code: var result = from tick in listTicks group tick by tick.timestamp.Hour; The datetime functions like day, hour, minute work fine but a specific interval wasn't possible for me. It is LINQ to objects. I have already got the list from the DB