How can I get the most frequent item in a pandas series?
Consider the series s
s = pd.Series(\"1 5 3 3 3 5 2 1 8 10 2 3 3 3
pandas.factorize and numpy.bincountThis is very similar to @jezrael's Numpy answer. The difference is the use of factorize and not numpy.unique
factorize returns an integer factorization and unique valuesbincount counts how many of each unique valueargmax identifies which bin or factor is the most fequentargmax to reference the most frequent value from the array of unique valuesi, r = s.factorize()
r[np.bincount(i).argmax()]
3