count the frequency that a value occurs in a dataframe column

后端 未结 13 1872
耶瑟儿~
耶瑟儿~ 2020-11-22 03:29

I have a dataset

|category|
cat a
cat b
cat a

I\'d like to be able to return something like (showing unique values and frequency)



        
13条回答
  •  长情又很酷
    2020-11-22 04:04

    n_values = data.income.value_counts()
    

    First unique value count

    n_at_most_50k = n_values[0]
    

    Second unique value count

    n_greater_50k = n_values[1]
    
    n_values
    

    Output:

    <=50K    34014
    >50K     11208
    
    Name: income, dtype: int64
    

    Output:

    n_greater_50k,n_at_most_50k:-
    (11208, 34014)
    

提交回复
热议问题