I want to create a table of grouped percentages across multiple columns using value_counts(normalize=True). I want to do so similar to below, except adding in the "normalize=True" portion, but not sure how to do so using groupby.agg. Any thoughts on how to do so without adding many more lines of code? My real data has a ton of columns, with a scale of 1-5 in each except the grouping columns.
Example below:
df = pd.DataFrame({'Country': ['FR', 'FR', 'GER','GER'],
'Foo': ['1', '2', '3', '1'],
'Bar': ['5', '5', '3', '1'],
'Baz': ['5', '1', '3', '4']})
df2=df.groupby('Country').agg(
{
'Foo': 'value_counts' ,
'Bar': 'value_counts',
'Baz': 'value_counts'
}
)