Skip to content

Instantly share code, notes, and snippets.

@aqd14
Created February 22, 2020 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aqd14/d71e1388c8622f73d72f22747c5239d2 to your computer and use it in GitHub Desktop.
Save aqd14/d71e1388c8622f73d72f22747c5239d2 to your computer and use it in GitHub Desktop.

Notes

Calculate the ratio of male grouped by occupation

occupation_grouped = users.groupby('occupation')

# Get back a multiindex pandas' Series containing ratio 
# for each gender in each occupation
gender_ratio = occupation_grouped.value_counts(normalize=True)

# we can then unpack the Series to get back a dataframe
# then get the Male column
gender_ratio.unpack()['M']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment