Group By and Aggregate
Easy
pandas
Spotify
DoorDash
Given a list of dictionaries, group the data by a specified column and compute the sum of another column for each group.
Example
data = [
{"dept": "eng", "salary": 100},
{"dept": "eng", "salary": 200},
{"dept": "sales", "salary": 150}
]
group_by_sum(data, "dept", "salary")
# => {"eng": 300, "sales": 150}
Test Cases
Python Editor
Output
Click "Run" to see results...