group-by

Using dplyr to group_by and conditionally mutate a dataframe by group

泄露秘密 提交于 2020-02-22 06:18:21
问题 I'd like to use dplyr functions to group_by and conditionally mutate a df. Given this sample data: A B C D 1 1 1 0.25 1 1 2 0 1 2 1 0.5 1 2 2 0 1 3 1 0.75 1 3 2 0.25 2 1 1 0 2 1 2 0.5 2 2 1 0 2 2 2 0 2 3 1 0 2 3 2 0 3 1 1 0.5 3 1 2 0 3 2 1 0.25 3 2 2 1 3 3 1 0 3 3 2 0.75 I want to use new column E to categorize A by whether B == 1, C == 2, and D > 0. For each unique value of A for which all of these conditions hold true, then E = 1, else E = 0. So, the output should look like this: A B C D E

Core Data - using Transient Properties in Group By

…衆ロ難τιáo~ 提交于 2020-02-14 06:41:11
问题 I'm creating a UITableView with some aggregated data. Along the way, Section Headings need to be used in sorting and grouping the table view cells. The issue is I would like to use a Transient Property within the NSFetchRequest to generate section headings & results sorts. The issue is that whilst setting up the NSFetchRequest I receive a ''NSInvalidArgumentException', reason: 'Invalid keypath player.fullName passed to setPropertiesToFetch'. The main entity for the NSFetchRequest is a Player

How to get the sum in a joined table when using group by - getting wrong results

倖福魔咒の 提交于 2020-02-08 10:59:29
问题 I have two tables orders and order_items . I need to group the results by days. But I also need to get the sum of energy_used for each day from another table. When I try that using a join, I get wrong order_sum for each day. Not sure what I am doing wrong. I am using joins because I would also like to sort by these columns later. Here is my orders table +----+-----------+---------+---------------------+ | id | order_sum | user_id | created_at | +----+-----------+---------+--------------------

How to use mongodb $group in java?

狂风中的少年 提交于 2020-02-08 02:33:07
问题 I have a collection processedClickLog in MongoDB. { "_id" : ObjectId("58ffb4cefbe21fa7896e2d73"), "ID" : "81a5d7f48e5df09c9bc006e7cc89d6e6", "USERID" : "206337611536", "DATETIME" : "Fri Mar 31 17:29:34 -0400 2017", "QUERYTEXT" : "Tom", "DOCID" : "www.demo.com", "TITLE" : "Harry Potter", "TAB" : "People-Tab", "TOTALRESULTS" : "1", "DOCRANK" : 1 } { "id": .... } I am trying to execute a complex query in java. My query is to get processedClickLog collection where TAB is not equal to People-Tab

Pandas: Drop duplicates in col[A] keeping row based on condition on col[B]

梦想与她 提交于 2020-02-06 10:04:34
问题 Given the dataframe: df = pd.DataFrame({'col1': ['A', 'A', 'A','B','B'], 'col2': ['type1', 'type2', 'type1', 'type2', 'type1'] , 'hour': ['18:03:30','18:00:48', '18:13:46', '18:11:29', '18:06:31'] }) col1 col2 hour A type1 18:03:30 # Drop this row as (A type1) already present A type2 18:00:48 A type1 18:13:46 # keep this row as (A type1) already present. B type2 18:11:29 B type1 18:06:31 I want to drop duplicates based on col1,col2. eg.(row(0): A type1, row(2): A type1) keeping only the row

Pandas: Drop duplicates in col[A] keeping row based on condition on col[B]

孤人 提交于 2020-02-06 10:03:13
问题 Given the dataframe: df = pd.DataFrame({'col1': ['A', 'A', 'A','B','B'], 'col2': ['type1', 'type2', 'type1', 'type2', 'type1'] , 'hour': ['18:03:30','18:00:48', '18:13:46', '18:11:29', '18:06:31'] }) col1 col2 hour A type1 18:03:30 # Drop this row as (A type1) already present A type2 18:00:48 A type1 18:13:46 # keep this row as (A type1) already present. B type2 18:11:29 B type1 18:06:31 I want to drop duplicates based on col1,col2. eg.(row(0): A type1, row(2): A type1) keeping only the row

Determining group size based entry and exit times of IDs in my df

限于喜欢 提交于 2020-02-06 05:00:06
问题 This gives me the entry and exit times of IDs in my df: minmax = merged_df.groupby(['id'])['date'].agg([min, max]) result id min max 4900 2019-09-17 08:43:06 2019-09-17 09:38:20 4909 2019-09-17 08:43:06 2019-09-17 09:16:00 4911 2019-09-17 08:43:06 2019-09-17 09:43:58 4965 2019-09-17 09:27:14 2019-09-17 09:38:28 5134 2019-09-17 09:34:26 2019-09-17 09:38:27 5139 2019-09-17 09:37:03 2019-09-17 09:46:19 5141 2019-09-17 09:37:22 2019-09-17 12:06:30 5163 2019-09-17 09:38:03 2019-09-17 10:18:29 5170

Typed group by in JavaScript/TypeScript - nested JSON to a typed nested array

拈花ヽ惹草 提交于 2020-02-05 04:28:26
问题 I have this list in my front-end typescript file: poMonths: 0: {id: 1, companyName: "company14", companyId: 14, flActive: true, purchaseMonth: "2019-12-15T00:00:00", purchaseMonthString: "Dec-2019" , year: 2019, month: "December"} 1: {id: 2, companyName: "company5", companyId: 5, flActive: true, purchaseMonth: "2019-12-15T00:00:00", …} 2: {id: 3, companyName: "company13", companyId: 13, flActive: true, purchaseMonth: "2019-11-15T00:00:00", …} 3: {id: 4, companyName: "company14", companyId: 14

Custom SQL GROUP BY Clause

懵懂的女人 提交于 2020-02-03 10:26:51
问题 I have a very customized SQL query that I am having problems implementing. I am using SQL-Server-2008. I have only one table in this query, but I am looking for very specific data. The requirements for this query are: For each DISTINCT PartNumber (column), I need to select the NEWEST (max) PO (column) to be selected. However, there is another column named "Receipt" where if it contains a value at all, then the PartNumber should be excluded all together. I am somewhat familiar with GROUP BY

Custom SQL GROUP BY Clause

给你一囗甜甜゛ 提交于 2020-02-03 10:25:13
问题 I have a very customized SQL query that I am having problems implementing. I am using SQL-Server-2008. I have only one table in this query, but I am looking for very specific data. The requirements for this query are: For each DISTINCT PartNumber (column), I need to select the NEWEST (max) PO (column) to be selected. However, there is another column named "Receipt" where if it contains a value at all, then the PartNumber should be excluded all together. I am somewhat familiar with GROUP BY