Skip to content

Instantly share code, notes, and snippets.

@panicpotatoe
Created March 12, 2019 02:54
Show Gist options
  • Select an option

  • Save panicpotatoe/5f0cd9bfbf8d7a984d34b08237af96a8 to your computer and use it in GitHub Desktop.

Select an option

Save panicpotatoe/5f0cd9bfbf8d7a984d34b08237af96a8 to your computer and use it in GitHub Desktop.
# Create a CrossTab from DataFrame, Assign the column names and row names
voter_tab = pd.crosstab(voters.race, voters.party, margins=True)
voter_tab.columns = ["democrat", "independent", "republican", "row_totals"]
voter_tab.index = ["asian", "black", "hispanic", "other", "white", "col_totals"]
# You can check the data of CrossTab by calling it
voter_tab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment