Pandas percentage of total with groupby
Update 2022-03 This answer by caner using transform looks much better than my original answer! df[‘sales’] / df.groupby(‘state’)[‘sales’].transform(‘sum’) Thanks to this comment by Paul Rougieux for surfacing it. Original Answer (2014) Paul H’s answer is right that you will have to make a second groupby object, but you can calculate the percentage in a simpler … Read more