I want to be able to pass the names of lists containing column names in a dataframe and apply after groupby different aggregating functions to each set.
So a naive and unsuccessful attempt was the following:
import pandas as pd
import seaborn as sns
mpg= sns.load_dataset('mpg')
variables_to_mean = ['cylinders', 'displacement']
variables_to_median = ['weight', 'horsepower']
mpg.groupby(['model_year', 'origin']).agg({ variables_to_mean : 'mean', variables_to_median : 'median'})
TypeError: unhashable type: 'list'
How can I achieve my objective?