To get percentage of total with groupby with Python Pandas, we can use the
/ operator to get the percentage with each item in a column.
For instance, we write
df['sales'] / df.groupby('state')['sales'].transform('sum')
to divide the values in the
sales column with the
sales values grouped by the
state value and summed together with