group-by Questions

4

I have performed a groupby on pandas and I want to apply a complex function which needs several inputs and gives as output a pandas Series that I want to burn in my original dataframe. this is a kn...
Unbound asked 8/9, 2016 at 7:17

2

Solved

CREATE TEMP TABLE wirednull ( id bigint NOT NULL, value bigint, CONSTRAINT wirednull_pkey PRIMARY KEY (id) ); INSERT INTO wirednull (id,value) VALUES (1,null); INSERT INTO wirednull (id,value) V...
Barrel asked 3/11, 2017 at 13:39

2

Solved

Let's say I have this data.frame (with 3 variables) ID Period Score 123 2013 146 123 2014 133 23 2013 150 456 2013 205 456 2014 219 456 2015 140 78 2012 192 78 2013 199 78 2014 133 78 2015 170 U...
Piper asked 20/1, 2015 at 12:54

9

Solved

I'm trying to solve #13 on http://www.sqlzoo.net/wiki/The_JOIN_operation "List every match with the goals scored by each team as shown. This will use "CASE WHEN" which has not been explained in an...
Pradeep asked 15/4, 2014 at 11:9

2

Solved

I have a table in sqlite. I am trying to get the first row of each group. Although there were earlier questions regarding the same. I couldn't find solution in sqlite. My table looks like this: ...
Husk asked 18/2, 2016 at 18:50

1

Solved

I have this code that generates a toy DataFrame (production df is much complex): import polars as pl import numpy as np import pandas as pd def create_timeseries_df(num_rows): date_rng = pd.date_...

3

Solved

I have an aggregation statement below: data = data.groupby(['type', 'status', 'name']).agg({ 'one' : np.mean, 'two' : lambda value: 100* ((value>32).sum() / reading.mean()), 'test2': lambda...
Misjoinder asked 8/6, 2015 at 20:12

3

Solved

Is there a pythonic way to group by a field and check if all elements of each resulting group have the same value? Sample data: datetime rating signal 0 2018-12-27 11:33:00 IG 0 1 2018-12-27 11:33...
Triable asked 27/12, 2018 at 21:7

2

Solved

I have a table with loads of fields, and I am trying to group by all except two values which I am summing on. I would like to do something like SELECT my_table.* except(value_1, value_2) , sum(v...
Pitchblack asked 20/2, 2019 at 17:42

8

Solved

SQL 2005, I have a table with a column 'ages_c', I need to group the records by age ranges. This is the query that I found on this site and it's getting me 90% there but the 'group by' is errorin...
Stricker asked 6/1, 2012 at 18:52

4

Solved

Linq newbie here, struggling with my first GroupBy query. I have a list of objects of type KeywordInstance which represents a keyword, and the ID of the database record to which the keyword was app...
Reach asked 6/11, 2013 at 13:10

2

Solved

work = pd.DataFrame({"JOB" : ['JOB01', 'JOB01', 'JOB02', 'JOB02', 'JOB03', 'JOB03'], "STATUS" : ['ON_ORDER', 'ACTIVE','TO_BE_ALLOCATED', 'ON_ORDER', 'ACTIVE','TO_BE_ALLOCATED'],...
Auscultation asked 8/5 at 8:24

4

Solved

In Entity Framework 6 I can use SqlFunctions.DatePart() method: var byWeek = data.GroupBy(x => SqlFunctions.DatePart("week", x.Date)); But these classes (DbFunctions and SqlFunctions are not ...
Elderberry asked 8/3, 2017 at 15:20

16

Solved

How do I find all rows in a pandas DataFrame which have the max value for count column, after grouping by ['Sp','Mt'] columns? Example 1: the following DataFrame: Sp Mt Value count 0 MM1 S1 a **3*...
Piperidine asked 29/3, 2013 at 14:48

5

Solved

I need to group by a calculated field in column SQL Server 2005/2008. I have the following query: select dateadd(day, -7, Convert(DateTime, mwspp.DateDue) + (7 - datepart(weekday, mwspp.DateDue))),...
Dumpish asked 9/4, 2013 at 11:48

2

Solved

There are a multitude of questions relating to the "Each GROUP BY expression must contain at least one column that is not an outer reference." error, and the inclusion of a constant value in the GR...
Bergstein asked 6/2, 2018 at 15:24

4

Solved

I have df: domain orgid csyunshu.com 108299 dshu.com 108299 bbbdshu.com 108299 cwakwakmrg.com 121303 ckonkatsunet.com 121303 I would like to add a new column with replaces domain column with num...
Hillhouse asked 17/3, 2016 at 14:19

6

I have a dataframe: pe_odds[ [ 'EVENT_ID', 'SELECTION_ID', 'ODDS' ] ] Out[67]: EVENT_ID SELECTION_ID ODDS 0 100429300 5297529 18.00 1 100429300 5297529 20.00 2 100429300 5297529 21.00 3 10042930...
Recurrent asked 12/10, 2014 at 10:1

33

Solved

I'm using MySQL 5.7.13 on my windows PC with WAMP Server. My problem is while executing this query SELECT * FROM `tbl_customer_pod_uploads` WHERE `load_id` = '78' AND `status` = 'Active' GROUP BY ...
Homework asked 27/1, 2017 at 5:27

12

Solved

Just curious about SQL syntax. So if I have SELECT itemName as ItemName, substring(itemName, 1,1) as FirstLetter, Count(itemName) FROM table1 GROUP BY itemName, FirstLetter This would be inc...
Corrody asked 1/10, 2010 at 16:46

7

Solved

I'm having this data frame: Name Date Quantity Apple 07/11/17 20 orange 07/14/17 20 Apple 07/14/17 70 Orange 07/25/17 40 Apple 07/20/17 30 I want to aggregate this by Name and Date to get sum of q...
Rogovy asked 24/7, 2017 at 12:58

5

Solved

This is my DataFrame: import pandas as pd df = pd.DataFrame( { 'a': ['x', 'x', 'x', 'x', 'y', 'y', 'y', 'y', 'z', 'z', 'z', 'p', 'p', 'p', 'p'], 'b': [1, -1, 1, 1, -1, 1, 1, -1, -1, -1, -1, 1, ...
Electrolier asked 5/3 at 4:56

5

Solved

Suppose we take a pandas dataframe... name age family 0 john 1 1 1 jason 36 1 2 jane 32 1 3 jack 26 2 4 james 30 2 Then do a groupby() ... group_df = df.groupby('family') group_df = group_df.aggr...
Craniate asked 21/11, 2013 at 13:38

63

Solved

What is the most efficient way to groupby objects in an array? For example, given this array of objects: [ { Phase: "Phase 1", Step: "Step 1", Task: "Task 1", Value: "5" }, { Phase: "Phase 1",...
Radish asked 21/1, 2013 at 20:18

2

Solved

I've a pandas dataframe with columns, department and employee_count. I need to sort the employee_count column in descending order. But if there is a tie between 2 employee_counts then they should b...
Reine asked 4/11, 2019 at 8:53

© 2022 - 2024 — McMap. All rights reserved.