How do I get the divided values of two columns that are a result from a groupby method
I currently have a dataframe that was made by the following example code
df.groupby(['col1', 'col2', 'Count'])[['Sum']].agg('sum')
which looks like this
col1 | col2 | Count | Sum |
---|---|---|---|
DOG | HUSKY | 600 | 1500 |
CAT | CALICO | 200 | 3000 |
BIRD | BLUE JAY | 1500 | 4500 |
I would like to create a new column which outputs the division of df['Sum'] and df['Count'] The expected data frame would look like this
col1 | col2 | Count | Sum | Average |
---|---|---|---|---|
DOG | HUSKY | 600 | 1500 | 2.5 |
CAT | CALICO | 200 | 3000 | 15 |
BIRD | BLUE JAY | 1500 | 4500 | 3 |
Any help would be greatly appreciated
Topic data-analysis pandas python
Category Data Science