I have a data frame and I would like to know how many times a given column has the most frequent value.
I try to do it in the following way:
items_co
You may also consider using scipy's mode
function which ignores NaN. A solution using it could look like:
from scipy.stats import mode
from numpy import nan
df = DataFrame({"a": [1,2,2,4,2], "b": [nan, nan, nan, 3, 3]})
print mode(df)
The output would look like
(array([[ 2., 3.]]), array([[ 3., 2.]]))
meaning that the most common values are 2
for the first columns and 3
for the second, with frequencies 3
and 2
respectively.