python - How to find out number of unique values in a column along with count of the unique values in a dataframe? -


as per following data set want no number of unique values , count of unique values.

my data set:

account_type gold gold platinum gold 

output :

no of unique values : 2 unique values : [gold,platinum] gold : 3 platinum :1  

use pd.value_counts

pd.value_counts(df.account_type)  gold        3 platinum    1 name: account_type, dtype: int64 

get number of unique well

s = pd.value_counts(df.account_type) s1 = pd.series({'nunique': len(s), 'unique values': s.index.tolist()}) s.append(s1)  gold                            3 platinum                        1 nunique                         2 unique values    [gold, platinum] dtype: object 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -