Skip to content

Instantly share code, notes, and snippets.

@gnurio
Created March 21, 2017 23:43
Show Gist options
  • Save gnurio/c3bd6d5fa9d67880014e5660df1368f8 to your computer and use it in GitHub Desktop.
Save gnurio/c3bd6d5fa9d67880014e5660df1368f8 to your computer and use it in GitHub Desktop.
How to calculate the mode for different categories in a DataFrame
import pandas as pd
from scipy.stats import mode
grouped_mod = df.pivot_table(values='The metric you need the mode for',columns='Category',aggfunc=mode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment