GroupBy pandas DataFrame and select most common value

Pandas >= 0.16 pd.Series.mode is available! Use groupby, GroupBy.agg, and apply the pd.Series.mode function to each group: source.groupby([‘Country’,’City’])[‘Short name’].agg(pd.Series.mode) Country City Russia Sankt-Petersburg Spb USA New-York NY Name: Short name, dtype: object If this is needed as a DataFrame, use source.groupby([‘Country’,’City’])[‘Short name’].agg(pd.Series.mode).to_frame() Short name Country City Russia Sankt-Petersburg Spb USA New-York NY The useful thing … Read more