9951 explained code solutions for 126 technologies


python-pandasHow to count unique values in a dataframe


import pandas as pd

data = pd.DataFrame({
  'Vendor': ['US', 'US', 'US', 'KR', 'KR'],
  'Phone': ['ip5', 'ip6', 'ip8', 'sms', 'xi'],
  'Phone Price': [204, 304, 204, 405, 204]
})

res = data['Phone Price'].nunique()ctrl + c
import pandas as pd

load Pandas module

pd.DataFrame

creates Pandas DataFrame object

'Phone Price'

column to count unique values in

.nunique()

returns unique values count in a given dataframe

res

will contain unique values count