vin67
August 14, 2021, 5:51am
1
Apologies I’m very new to observable but I’m stumped and I’m sure its simple for many here.
Is there something similar to pandas group by, aggregate and apply a function to get counts and percentages of total rows?
eg group all rows by school_type, count and create a percentage of the total
df.groupby(‘dem_school_type_by_age_range’).agg({‘dem_school_type_by_age_range’: ‘count’}).apply(lambda x: 100*x/x.sum())
I’ve been looking for a while to figure out in vegalite, the data transform function… or do it inside of observables javascript but I can;t figure it out.
d3.rollup(…) is part of the standard library of Observablehq.
As its name suggests, d3.group groups values by key. It returns a map from key to the corresponding array of values from the input. For example, say you have a table of highly-paid athletes: To group the athletes by sport: Now you can query the map...
1 Like
Here’s a notebook showing how to use either Arquero or D3 for this. The Arquero code looks a lot like Pandas:
2 Likes
vin67
August 17, 2021, 1:39am
4
This is extremely helpful! Very clear. Thank you for taking the time to explain two alternative methods.
1 Like