aggregate-functions

Ratio after a groupby in pyspark

Ratio after a groupby in pyspark Question: I have a pyspark df like this +————+————-+ |Gender | Language| +————+————-+ | Male| Spanish| | Female| English| | Female| Indian| | Female| Spanish| | Female| Indian| | Male| English| | Male| English| | Female|Latin Spanish| | Male| Spanish| | Female| English| | Male| Indian| | Male| Catalan| …

Total answers: 1

Exclude groups containing just one row instance

Exclude groups containing just one row instance Question: I have a pandas table like below with groupby applied to get Groups 0, 1 and 2 as follows: Group 0 Group 1 Group 2 Count A X1 577.5000 6 894.8700 2 X2 2697.3100 48 2697.3100 1 B3 2697.3100 30 B RO2 92.46 3 C C12 34.2700 …

Total answers: 2

Pandas – compute previous custom quarter wise total revenue and reshape table

Pandas – compute previous custom quarter wise total revenue and reshape table Question: I have a dataframe like as below df = pd.DataFrame( {‘stud_id’ : [101, 101, 101, 101, 101, 102, 102, 102], ‘sub_code’ : [‘CSE01’, ‘CSE01’, ‘CSE01’, ‘CSE01’, ‘CSE02’, ‘CSE02’, ‘CSE02’, ‘CSE02’], ‘ques_date’ : [’10/11/2022′, ’06/06/2022′,’09/04/2022′, ’27/03/2022′, ’13/05/2010′, ’10/11/2021′,’11/1/2022′, ’27/02/2022′], ‘revenue’ : [77, 86, …

Total answers: 1

elegant way to agg and transform together in pandas groupby

elegant way to agg and transform together in pandas groupby Question: I have a dataframe like as below df = pd.DataFrame( {‘stud_id’ : [101, 101, 101, 101, 101, 101, 101, 101], ‘sub_code’ : [‘CSE01’, ‘CSE01’, ‘CSE01’, ‘CSE01’, ‘CSE02’, ‘CSE02’, ‘CSE02’, ‘CSE02’], ‘ques_date’ : [’13/11/2020′, ’10/1/2018′,’11/11/2017′, ’27/03/2016′, ’13/05/2010′, ’10/11/2008′,’11/1/2007′, ’27/02/2006′], ‘marks’ : [77, 86, 55, 90, …

Total answers: 1

Django count records with aggregate

Django count records with aggregate Question: I have field like this: I want all records count with all tags for example sale = Sale.objects.using(‘read_rep’) .filter(tags__name__in=[‘Device’,’Mobile’]) .aggregate( **{total: Count(‘pk’, for status, _ in [‘Device’,’Mobile’]} ) Device – 2 Mobile-5 It is difficult to count records with all tags because tags are being store in only one …

Total answers: 1

Firestore Python SDK – count() aggregation

Firestore Python SDK – count() aggregation Question: I’m using Firebase Firestore in my Python project (with their official Python SDK) and having trouble performing count() aggregation. This funciton is supported according to their docs. However, they do not provide Python example ( they do in other parts of documentation ). I tried to play with …

Total answers: 2

aggregate based on if column values exist

aggregate based on if column values exist Question: I have a dataframe and would like to aggregate based on if some values in column Result exist or not. So if for any ìndex1 and ìndex2 there is an A then my total_result column should be A. If there is no A but there is a …

Total answers: 1

Getting row sums for specific columns – Python

Getting row sums for specific columns – Python Question: I created a simple dataset df with three columns, Area, Year_2010, Year_2020. The related code: # Import pandas library import pandas as pd # initialize list of lists data = [[‘Netherlands’, 100, 200], [‘Belgium’, 15, 80], [‘Germany’, 125, 300]] # Create the pandas DataFrame df = …

Total answers: 2