Nov-07-2023, 02:26 PM
Hi all,
I'm not appreciating the functionality of the .agg() method. This creates a df:
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!