Groupby: una pequeña introducción

[Bajar de Kaggle el dataset the Nobel Price] (https://www.kaggle.com/datasets/imdevskp/nobel-prize)

Splitting the Original Object into Groups

To briefly inspect the resulting GroupBy object and check how exactly the groups were split, we can extract from it the groups or indices attribute. Both of them return a dictionary where the keys are the created groups and the values are the lists of axis labels (for the groups attribute) or indices (for the indices attribute) of the instances of each group in the original DataFrame:

Los indices se utilizan para buscar que observaciones (filas) que corressponden a cada grupo

El método agg trabaja con los subgrupos creados por groupby y devuelve un output an nivel de subgrupo.

Observar que transform, trabaja a nivel de los subgrupos creados por groupby pero devuelve un valor para cada observacion del dataframe original

Ejemplo:

With transformation methods, we can also replace missing data with the group mean, median, mode, or any other value:

Observar lo que tiene la función lambda

x.fillna(x.mode()[0])

No queda muy claro ese cero detras: Probemos dos cosas: Primero:

df['gender'].mode()

Segundo

df['gender'].mode()

Ver cual es la diferencia en cada uno

Filtration

Filtration methods discard the groups or particular rows from each group based on a predefined condition and return a subset of the original data.