How to get the most frequent row in table
With NumPy's np.unique
-
In [92]: u,idx,c = np.unique(df.values.astype(str), axis=0, return_index=True, return_counts=True)In [99]: df.iloc[[idx[c.argmax()]]]Out[99]: col_1 col_2 col_30 1 1 A
If you are looking for performance, convert the string column to numeric and then use np.unique
-
a = np.c_[df.col_1, df.col_2, pd.factorize(df.col_3)[0]]u,idx,c = np.unique(a, axis=0, return_index=True, return_counts=True)