aggregate

pandas iterate over many dataframe and create list of occurance per key

pandas iterate over many dataframe and create list of occurance per key Question: I have the few hundreds of dataframe with the same sturcture. I want to aggregate per key as follows: For the list columns – create a list of lists (where each list is the value of specific dataframe) For example in case …

Total answers: 1

Groupby and concatenate unique values by separator in Pandas dataframa

Groupby and concatenate unique values by separator in Pandas dataframa Question: I have following pandas dataframe. org_id org_name location_id loc_status city country 0 100023310 advance GmbH LOC-100052061 ACTIVE Planegg Germany 1 100023310 advance GmbH LOC-100032442 ACTIVE Planegg Germany 2 100023310 advance GmbH LOC-100042003 INACTIVE Planegg Germany 3 100004261 Beacon Limited LOC-100005615 ACTIVE Tunbridge Wells United …

Total answers: 3

In Pandas, how to retrieve the rows which created each group, after aggregation and filtering?

In Pandas, how to retrieve the rows which created each group, after aggregation and filtering? Question: Let import pandas as pd df = pd.DataFrame( { ‘a’: [‘A’, ‘A’, ‘B’, ‘B’, ‘B’, ‘C’], ‘b’: [True, True, True, False, False, True] } ) print(df) groups = df.groupby(‘a’) # "A", "B", "C" agg_groups = groups.agg({‘b’:lambda x: all(x)}) # …

Total answers: 3

New Column based on aggregation from different df with specific conditions

New Column based on aggregation from different df with specific conditions Question: I have two data frames: df1 includes rows with a date df2 includes rows with type and date I would like to create column "b" in df1, that is a list of all types (including duplicates) of df2 with df2.date less then df1.date …

Total answers: 1

How to select the first value that is not NaN after using groupby().agg()?

How to select the first value that is not NaN after using groupby().agg()? Question: I have the following code: df.groupby(["id", "year"], as_index=False).agg({"brand":"first", "color":"first"}) However, I have some values that are NaN. I want to select the first value that is not NaN. Suppose my dataframe looks like this: id year brand color 001 2010 NaN …

Total answers: 1

django Count aggregate is not working as I intended

django Count aggregate is not working as I intended Question: It’s a code that reproduces the problem I experienced. models.py from django.db import models class User(models.Model): pass class Group(models.Model): users = models.ManyToManyField( User, related_name=’groups’, ) class Notice(models.Model): groups = models.ManyToManyField( Group, related_name=’notices’, ) tests.py from django.test import TestCase from tests.models import User, Group, Notice from …

Total answers: 1

Is there pandas aggregate function that combines features of 'any' and 'unique'?

Is there pandas aggregate function that combines features of 'any' and 'unique'? Question: I have a large dataset with similar data: >>> df = pd.DataFrame( … {‘A’: [‘one’, ‘two’, ‘two’, ‘one’, ‘one’, ‘three’], … ‘B’: [‘a’, ‘b’, ‘c’, ‘a’, ‘a’, np.nan]}) >>> df A B 0 one a 1 two b 2 two c 3 …

Total answers: 5