Advanced Aggregation [1/2]
Sometimes one aggregate function is not enought to make complete conclusions. For instance, we may need to get not only minimal, but also maximal value per group. Can pandas
handle it? Surely, it can!
If you want to apply more than one aggregate function to each group, use the .agg()
method. Pass a list of function names (as strings!) you want to apply to each group as the parameter. For instance, we can get the minimal and maximal price for each value of the 'roomh'
column (number of rooms).
12345678# Importing the library import pandas as pd # Reading the file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/f2947b09-5f0d-4ad9-992f-ec0b87cd4b3f/data4.csv') # Minimal and maximal prices for each dwelling type print(df.groupby('roomh')['valueh'].agg(['min', 'max']))
Tak for dine kommentarer!
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat
Awesome!
Completion rate improved to 2.56
Advanced Aggregation [1/2]
Stryg for at vise menuen
Sometimes one aggregate function is not enought to make complete conclusions. For instance, we may need to get not only minimal, but also maximal value per group. Can pandas
handle it? Surely, it can!
If you want to apply more than one aggregate function to each group, use the .agg()
method. Pass a list of function names (as strings!) you want to apply to each group as the parameter. For instance, we can get the minimal and maximal price for each value of the 'roomh'
column (number of rooms).
12345678# Importing the library import pandas as pd # Reading the file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/f2947b09-5f0d-4ad9-992f-ec0b87cd4b3f/data4.csv') # Minimal and maximal prices for each dwelling type print(df.groupby('roomh')['valueh'].agg(['min', 'max']))
Tak for dine kommentarer!