Python Forum
What exactly does .agg() do?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What exactly does .agg() do?
#1
Hi all,

I'm not appreciating the functionality of the .agg() method. This creates a df:

import pandas as pd

name = ['Bella', 'Charlie', 'Lucy', 'Cooper', 'Max', 'Stella', 'Bernie']
breed = ['Labrador', 'Poodle', 'Chow Chow', 'Schnauzer', 'Labrador', 'Chihuahua', 'St. Bernard']
color = ['Brown', 'Black', 'Brown', 'Gray', 'Black', 'Tan', 'White']
height_cm = [56, 43, 46, 49, 59, 18, 77]
weight_kg = [25, 23, 22, 17, 29, 2, 74]
dob = ['2013-07-01', '2016-09-16', '2014-08-25', '2011-12-11', '2017-01-20', '2015-04-20', '2018-02-27']
dogs_dict = {'Name':name, 'Breed':breed, 'Color':color, 'Height (cm)':height_cm, 'Weight (kg)':weight_kg, 'Date of Birth':dob}
dogs = pd.DataFrame(dogs_dict)
Now, with or without the .agg() method, these do the same thing:

def pct30(column):
    return column.quantile(0.3)

print(pct30(dogs[['Height (cm)', 'Weight (kg)']]))
print()
print(dogs[['Height (cm)', 'Weight (kg)']].agg(pct30))
What is the reason to use .agg(), exactly? Thanks!
Reply


Messages In This Thread
What exactly does .agg() do? - by Mark17 - Nov-07-2023, 02:26 PM
RE: What exactly does .agg() do? - by noisefloor - Nov-07-2023, 04:04 PM
RE: What exactly does .agg() do? - by Mark17 - Nov-07-2023, 06:33 PM
RE: What exactly does .agg() do? - by snippsat - Nov-07-2023, 07:07 PM
RE: What exactly does .agg() do? - by deanhystad - Nov-07-2023, 07:09 PM
RE: What exactly does .agg() do? - by noisefloor - Nov-08-2023, 07:01 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020