group-by

Adding total row to pandas DataFrame groupby

♀尐吖头ヾ 提交于 2019-12-24 18:13:25
问题 I am aware of this link but I didn't manage to solve my problem. I have this below DataFrame from pandas.DataFrame.groupby().sum() : Value Level Company Item 1 X a 100 b 200 Y a 35 b 150 c 35 2 X a 48 b 100 c 50 Y a 80 and would like to add total rows for each level of index that I have to get: Value Level Company Item 1 X a 100 b 200 Total 300 Y a 35 b 150 c 35 Total 520 Total 820 2 X a 48 b 100 c 50 Total 198 Y a 80 Total 80 Total 278 Total 1098 As request level = list(map(int, list(

MySQL - Dynamic Pivot Table Grouping Issue

纵然是瞬间 提交于 2019-12-24 17:22:53
问题 I'm trying to create a dynamic pivot table using a MySQL Prepared Statement I've put together from the numerous other questions about MySQL pivot tables. But I'm not getting the output I'm expecting. My tables look like this: skills contains every "skill" that an employee could be trained on | id | skill | expiry_date | ----+---------+------------- | 1 | SkillA | 2016-07-01 | | 2 | SkillB | 2016-06-01 | | 3 | SkillC | 2016-04-01 | employee_skills contains a log of the date which an employee

Oracle SQL Group By if

五迷三道 提交于 2019-12-24 16:58:56
问题 In my application I log the file opening in the following table: TESTID SITE LATEST_READ READ_COUNT FILE_ORIGIN_ID ------------- ---------- ----------- ---------- -------------- File1 |Site1 |02/05/13 | 2| 1 File1 |Site2 |22/01/14 | 3| 2 File2 |Site1 |02/06/14 | 8| 0 File3 |Site1 |19/09/14 | 17| 0 File4 |Site2 |19/09/14 | 14| 2 File4 |Site2 |19/09/14 | 34| 1 File4 |Site3 |19/09/14 | 10| 0 File5 |Site2 |19/09/14 | 44| 2 File5 |Site3 |19/09/14 | 1| 2 I want to get the sum of the read count per

Pandas duplicates groupby

。_饼干妹妹 提交于 2019-12-24 16:44:08
问题 I've a Pandas dataframe, and some numerical data about some people. What I need to do is to find people that appare more than one time in the dataframe, and to substitute all the row about one people with one row where the numeric values are the sum of the numeric values of the rows before in some columns, and the minimum of this values in other. I know how to do the sum using groupby() and sum() but not how to do different thing for the different columns Example: Names Column1 Column2

MySQL query to return multiple summed columns

Deadly 提交于 2019-12-24 16:23:02
问题 I have the following data in my SQL table. uid user category count date -------------------------------------------------- 1 henry RED 4 2013-05-01 2 john BLUE 3 2013-05-01 3 alice RED 5 2013-05-01 4 eric GREEN 2 2013-05-02 5 eric BLUE 2 2013-05-02 6 john RED 3 2013-05-02 7 henry GREEN 2 2013-05-02 8 eric RED 3 2013-05-03 9 john BLUE 5 2013-05-03 I would like a query that gives me back the following data category 2013-05-01 2013-05-02 2013-05-03 -----------------------------------------------

GROUP BY interval overlapping timestamp MySQL query

瘦欲@ 提交于 2019-12-24 14:38:00
问题 I've been reading other questions and had no luck. I have a table with columns (stamp,value). The 'stamp' column stores hourly timestamps. What I'm trying to do is to retrieve SUM(value) for intervals of 24 hours depending on a range of timestamps specified in the query: SELECT stamp, Sum(value) FROM table WHERE stamp >= Date_sub('2012-12-02 05:00:00', INTERVAL 1 day) AND stamp < '2013-01-01 05:00:00' GROUP BY Date(stamp) The result I'm looking for would look like this: stamp value 2012-12-02

Summer in Greece, vol.2

早过忘川 提交于 2019-12-24 14:28:43
问题 Following this qeustion: Summer in Greece with SPARQL, since my memory runs out when executing this query, I would like to constrain the query between two regional units, but I can't group them: SELECT * #?municipality (?bwCount1+?bwCount2 as ?bwCount) WHERE { { SELECT (COUNT(?bw) as ?bwCount1) WHERE { ?regional_unit geo:έχει_επίσημο_όνομα "ΠΕΡΙΦΕΡΕΙΑΚΗ ΕΝΟΤΗΤΑ ΗΡΑΚΛΕΙΟΥ" . ?municipality1 geo:ανήκει_σε ?regional_unit . ?municipality1 geo:έχει_γεωμετρία ?geometry . ?bw geos:hasGeometry ?bw_geo

GROUP BY clause sees all VARCHAR fields as different

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 14:08:36
问题 I have witnessed a strange behaviour while trying to GROUP BY a VARCHAR field. Let the following example, where I try to spot customers that have changed name at least once in the past. CREATE TABLE #CustomersHistory ( Id INT IDENTITY(1,1), CustomerId INT, Name VARCHAR(200) ) INSERT INTO #CustomersHistory VALUES (12, 'AAA') INSERT INTO #CustomersHistory VALUES (12, 'AAA') INSERT INTO #CustomersHistory VALUES (12, 'BBB') INSERT INTO #CustomersHistory VALUES (44, '444') SELECT ch.CustomerId,

SQL Query for time intervals. Syntax errors.

流过昼夜 提交于 2019-12-24 13:56:08
问题 This is the case where a seemingly simple exercise turned to be nothing but. I couldn't even get my syntax straight. Readings table contains coordinates and time readings for multiple users. All I want at this time to organize it as consecutive time intervals for each user. Data : CREATE TABLE [Readings] ( user_id varchar(10), reading_time int, x decimal(10,2), y decimal(10,2) ); INSERT INTO Readings VALUES ('u1', 60, 345, 400), ('u1', 100, 560,300), ('u2', 35, 1024, 250), ('u1', 90, 450, 450

SQL join two simple query with count and groupby

谁说胖子不能爱 提交于 2019-12-24 13:39:26
问题 hello i have 2 queries and i wanna join together but i don't know how... SELECT *, count(*) as invii FROM professionisti JOIN preventivi_invii ON professionisti.email=preventivi_invii.email GROUP BY professionisti.email HAVING invii> 300 SELECT *, count(*) as acquisti FROM professionisti JOIN contatti_acquistati ON professionisti.email=contatti_acquistati.email GROUP BY professionisti.email HAVING acquisti> 5 the problem for me is multiple count and the group by with same column. thank u 回答1: