36,973 questions
0
votes
2
answers
95
views
Grouping of records in case values are null
We have got a table with a identifier, a key/value pairs and a start and end timestamp which indicates the valid period for the values.
MASTER_WORK_ORDR_ID
START_TS
END_TS
WORK_ORDR_ID_CTXT
...
1
vote
5
answers
86
views
Grouping rows, and then deleting only a sub range (based on their dates) from each of those groups
I use Postgres on my web server in order to record incoming queries into a table calls2, basically writing a single row each time with lots of repeating information, such as a date field ("when&...
3
votes
3
answers
180
views
Filter a pandas df: per group, keep only non-null rows if we have them, else keep a single null row
Hopefully the title is reasonably intuitive, edits welcome. Say I have this dataframe:
df = pd.DataFrame({'x': ['A', 'B', 'B', 'C', 'C', 'C', 'D', 'D'],
'y': [None, None, 1, 2, 3, 4,...
1
vote
2
answers
96
views
Grouping data by season in R when winter includes December from the previous year
I have a dataset called TotalPhosphorus, and I want to assign seasons to each observation. However, I need the winter season to include December from the previous year and January–March from the ...
1
vote
1
answer
56
views
How to reverse a DolphinDB table aggregated by group by + toArray back to its original form?
I have an in - memory DolphinDB table created as follows:
ticker = `AAPL`IBM`IBM`AAPL`AMZN`AAPL`AMZN`IBM`AMZN
volume = 106 115 121 90 130 150 145 123 155;
t = table(ticker, volume);
t;
The output of ...
0
votes
1
answer
89
views
R arrange after grouping [duplicate]
I have noticed that although
df %>%
group_by(firm) %>%
arrange(week) %>%
mutate(lag_sales = lag(sales)) %>%
ungroup()
ignores the grouping but calculates the correct lags as the ...
0
votes
0
answers
27
views
Python display and count unique elements from a dataset [duplicate]
I have a dataset populated from an API call to Splunk.
The dataset contains the following:
time
destip
destport
transport
2025-09-17 22:03:09
172.16.5.1
53
UDP
2025-09-17 22:03:10
172.16.5.1
53
UDP
...
4
votes
0
answers
137
views
Hourly true average between timestamps [closed]
I’m storing IoT readings in a GridDB container and need one row per hour with the true average of the points that actually fall inside each hour (not interpolated values):
ts_bucket ...
1
vote
1
answer
109
views
group_by with polars concatenating values
I have a polars dataframe that I want to group by and concatenate the unique values in as a single entry.
in pandas, I go:
def unique_colun_values(x):
return('|'.join(set(x)))
dd=pd.DataFrame({'...
1
vote
2
answers
99
views
Remove items within pandas DataFrameGroupBy groups
I have a dataframe df made up of n columns which are groups and one, "data". This dataframe is then grouped on the n group columns.
df = pd.DataFrame(data={"g0": ["foo", ...
7
votes
3
answers
438
views
How to sort pandas groups by (multiple/all) values of the groups?
I am trying to do a somewhat complicated group and sort operation in pandas. I want to sort the groups by their values in ascending order, using successive values for tiebreaks as needed.
I have read ...
0
votes
2
answers
69
views
DAX concatenate list of a column value (ex. contract) grouped by date
I'm trying to create a list of contracts that expire by dates. I looked on the many sites for a solution.
I have a measure that calculates the date and i need calculated table with a summurazed ...
2
votes
2
answers
86
views
Pandas dt accessor or groupby function returning decimal numbers instead of integers in index labels where some series values NA
We're trying to group up date counts by month and index values are returning as decimals instead of integers when series contain any number of NaTs / na values.
Simplified reproducible example:
import ...
0
votes
1
answer
32
views
How to group by a column and calculate correlation coefficients between multiple columns?
I'm encountering some issues when trying to perform grouped correlation calculations in DolphinDB. Here's my scenario:
I'm using DolphinDB to calculate correlations between multiple columns in a table....
1
vote
2
answers
104
views
How do I get the last valid (non-null, non-zero) value per day in a time-series SQL query?
I’m working with time-series data in SQL Server and need to retrieve the last valid value for each day. A valid value is defined as one that is non-null and not zero.
The challenge is that data points ...
1
vote
1
answer
69
views
TimeScaleDb/Postgres: Materialized Views(COGG): GROUP BY: group by certain field values
What I'm currently doing is this:
SELECT
time_bucket('60 min', raw_data.timestamp) AS time_60min,
COUNT(raw_data.vehicle_class) AS "count",
raw_data.vehicle_class AS "...
2
votes
1
answer
282
views
Dataframe behavior: Pandas 1.1.5 vs 2.3.0
I recently had to update the virtual environment for one of my libraries from Python 3.7 to 3.10, which also involved updating Pandas from 1.1.5 to 2.3.0.
In the previous virtual environment, this ...
0
votes
1
answer
77
views
MS Access Reports: How do I group by two fields on the same level (OR?)
I have a database of music manuscripts that looks like the below diagram.
A 'Source item' belongs to a certain manuscript (source). A source item is then categorized as EITHER a 'Section' of a 'Piece' ...
2
votes
1
answer
53
views
Only display the top N rows in a dataframe that was aggregated with statistical functions but keep the primary sort
Suppose I have this:
ISresult = h25.groupby(['month','impactedservice']).agg({'resolvetime': ['count','median','mean', 'min', 'max','std']})
The column list looks like this:
[('resolvetime', 'count'),...
0
votes
3
answers
120
views
Min and Max value on multiple cells group by third column value
I would like to extract the MIN and MAX from multiple columns (start_1, end_1, start_2, end_2) group by "Name"
I have data that looks like this:
start_1 end_1 start_2 end_2 name
100 ...
0
votes
1
answer
95
views
Does BigQuery `GROUP by grouping set` perform better than `Group By Union`
BigQuery has a newly GROUP by grouping set [1].
It is syntax simpler than the traditional Group By Union approach. I wonder if it also performs much better, because grouping set only scan the source ...
0
votes
2
answers
80
views
How do I sum over different combinations of variables in DBV?
Following is my table. I want to sum across all different combinations and put the sum in separate columns, not in the same column.
data:
Subject
Var1
Var2
Var3
Var4
Constant1
Constant2
ONE
1
2
1
1
A
...
1
vote
3
answers
91
views
In sql, group by using similar group_name
How can I perform a
GROUP BY
in SQL when the group_name values are similar but not exactly the same?
In my dataset, the group_name values may differ slightly (e.g., "Apple Inc.", "...
1
vote
2
answers
62
views
Trying to use groupby on a Pandas DF to do a reverse lookup
I am trying to figure out how to code a reverse look up in pandas dataframe using groupby and looking for the owner of a max time.
`
import pandas as pd
df = {'Name': ['Mike', 'Lilly', 'Frank', 'Jane',...
0
votes
0
answers
39
views
calculating First time right (%) using call logs dataset from a contact center
I am calculating the First Time Resolution (FTR) percentage from call logs using the following Python code with pandas and numpy. When I run the code on one CSV file (calls_logs_cleaned_2025-05-02.csv)...