Skip to content

Instantly share code, notes, and snippets.

@aniruddha27
Created May 6, 2020 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aniruddha27/c712cd68b5b0bbff1422b9869b14c2ab to your computer and use it in GitHub Desktop.
Save aniruddha27/c712cd68b5b0bbff1422b9869b14c2ab to your computer and use it in GitHub Desktop.
#displays the subtotal using margins and margins_name
# margins is a boolean field that should be made True if total values need to be printed.
# margins_name is the optional field where you can name the margin row/column in your grouped table.
table = pd.pivot_table(df,index=['Sex'],columns=['Pclass'],values=['Survived'],aggfunc=np.sum, margins=True, margins_name='Total_Survived')
table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment