Skip to main content

Questions tagged [group-by]

GROUP BY is a command in the SQL relational database standard, and pandas, for collapsing a group of rows that share common field value(s) into a single row. Aggregate functions can be performed on other fields in the group, such as SUM() or AVG(), to collate related data into a single value.

2 votes
1 answer
45 views

number every first unique piece in each group

In each group, each 1st unique item should be given a different number in new column 'num'. I can form the groups but I don't know how to number the unique pieces. Is there a way to do that ? Unique ...
mxplk's user avatar
  • 57
0 votes
0 answers
27 views

JSON serialization with a group by query ... how to?

I have an API endpoint to pull a big JSON blob from one of my models, and it works, but I'd like to improve it. The current implementation is below, and mostly just works using built in associations. ...
valenumr's user avatar
0 votes
2 answers
33 views

Mutate/cut to bin grouped data by grouped break points

I have two data-frames, each with the same groups. The first data frame consists of the base data, the second an independent set of break points for each group. I want to use those break points to ...
Jaken's user avatar
  • 93
1 vote
1 answer
125 views
+50

Permutation summation in Pandas dataframe growing super exponentially

I have a pandas dataframe that looks like import pandas as pd data = { "Race_ID": [2,2,2,2,2,5,5,5,5,5,5], "Student_ID": [1,2,3,4,5,9,10,2,3,6,5], "theta": [8,9,2,...
Ishigami's user avatar
  • 223
0 votes
0 answers
32 views

sum groupby and add or sub row before to groupby and add row after to groupby

I have a dataframe and I would like to get summing values for every [group] with one row Values before ('subtract' & 'add') and one row after ('BEGUZE_UE') the group. (A group can contain ...
mxplk's user avatar
  • 57
0 votes
1 answer
33 views

Remove string from column across group of rows in another column

I would like to remove a string from one column across a group of rows in another column. In the below reprex, I would like to remove the string in snippet from the string in text in any row in the ...
maia-sh's user avatar
  • 557
0 votes
2 answers
33 views

make groups by a dictionary in R

I have the task of identifying the group to which a sentence belongs according to the use of specific words, for example identifying which color has been used to describe an animal. I have a ...
Dan G's user avatar
  • 21
0 votes
0 answers
44 views

Column 'f.revenue' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause

I want to calculate the median of revenue but show the following error and I don't understand why: Column 'finance.revenue' is invalid in the select list because it is not contained in either an ...
Channi's user avatar
  • 1
1 vote
4 answers
48 views

Apply Group by to dictionary value

I have a Dictionary which key of string type and value of list of integer type, like this: Dictionary<string, List<int>>. Lets say I add elements to it: Dictionary<string, List<int&...
sst's user avatar
  • 23
1 vote
1 answer
22 views

SQL Group By Then Filter [duplicate]

I have two tables as follows: Table A : contacts Contact_Primary_Num Displayed_Name 1 Smith, Joe 2 Doe, Donna 3 Jerry, Tom 4 Crocker, Betty Table B : contact_notes Contact_Note_Primary_Num ...
Progolfer79's user avatar
0 votes
1 answer
21 views

SQL QUERY reporting production yield by time range Group by

Hi I am new to the SQL world. I want to calculate the system on and off time and total production yield of each run time. Thanks. Here is exmple of the raw data. timestamp system status yield lbs/s ...
NPE's user avatar
  • 1
1 vote
2 answers
74 views

How to group by one column and then a second column to summarize

I have a data frame with two ID fields similar to the following: ID 1 ID 2 Name 5 6 Apple1 5 7 Applee 6 7 Applye 3 7 Apple2 I am trying to first group by the first ID then by the second, so that ...
Jennifer Benjamin's user avatar
0 votes
1 answer
32 views

Calculating average value by grouping by multiple variables using Group_by function in R studio [duplicate]

I have a table set up like this Site Replicate Species Value A A A A 1 A A B 2 A B A 3 B A A 3 B A B 4 B B B 6 B B C 2 C A A 5 C A B 6 And I want to calculate the average of value A ...
capthom_obvious's user avatar
0 votes
1 answer
42 views

Get aggregates for a dataframe with different combinations

Total pyspark noob here. I have a dataframe similar to this: df = spark.createDataFrame([ Row(ttype='C', amt='12.99', dt='2024/01/01'), Row(ttype='D', amt='21.99', dt='2024/02/15'), Row(ttype='C'...
mithun_daa's user avatar
  • 4,374
0 votes
1 answer
46 views

Pandas, How can I group column 1 by column 2 with column 1's absolute max values without changing column 1 to absolute values?

So lets say I got a df_1 like this: Floor UV 1 1 -2 2 1 3 3 1 -5 4 1 4 5 2 14 6 2 -15 And I have written this code: output_df = df_1.loc[df_1.groupby(&...
Hür Doğan ÜNLÜ's user avatar

15 30 50 per page
1
2 3 4 5
1871