I've got a set of survey responses that I'm trying to analyze with pandas. My goal is to find (for this example) the most common gender in each county in the US, so I use the following code:
import pandas as pd
from scipy import stats
file['sex'].groupby(file['county']).agg([('modeSex', stats.mode)])
The output is:
How can I unpack this to only get the mode value and not the second value that tells how often the mode occurs?
Here is a sample of the data frame:
county|sex
----------
079 | 1
----------
079 | 2
----------
079 | 2
----------
075 | 1
----------
075 | 1
----------
075 | 1
----------
075 | 2
Desired output is:
county|modeSex
----------
079 | 2
----------
075 | 1