Created
March 21, 2017 23:43
-
-
Save gnurio/c3bd6d5fa9d67880014e5660df1368f8 to your computer and use it in GitHub Desktop.
How to calculate the mode for different categories in a DataFrame
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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