How to get the number of the most frequent value in a column?

前端 未结 6 1830
夕颜
夕颜 2020-12-24 02:02

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         


        
6条回答
  •  别那么骄傲
    2020-12-24 02:39

    To continue to @jonathanrocher answer you could use mode in pandas DataFrame. It'll give a most frequent values (one or two) across the rows or columns:

    import pandas as pd
    import numpy as np
    df = pd.DataFrame({"a": [1,2,2,4,2], "b": [np.nan, np.nan, np.nan, 3, 3]})
    
    In [2]: df.mode()
    Out[2]: 
       a    b
    0  2  3.0
    

提交回复
热议问题