Count Unique Values in Pandas DataFrame Column ๐งฎ
Learn how to count unique elements in a pandas DataFrame column using the nunique() function with an example.

Statistics Globe
486 views โข Oct 26, 2022

About this video
How to count the number of unique elements in a pandas DataFrame column in the Python programming language. More details: https://statisticsglobe.com/count-unique-values-column-pandas-dataframe-python
Python code of this video:
import pandas as pd # Load pandas library
data = pd.DataFrame({'values':[1, 2, 3, 1, 1, 1, 1, 2, 2], # Create example DataFrame
'groups':['a', 'a', 'a', 'a', 'b', 'b', 'c', 'c', 'c']})
print(data) # Print example DataFrame
count_unique = data['values'].nunique() # Apply unique function
print(count_unique) # Print count of unique values
# 3
Follow me on Social Media:
Facebook โ Statistics Globe Page: https://www.facebook.com/statisticsglobecom/
Facebook โ R Programming Group for Discussions & Questions: https://www.facebook.com/groups/statisticsglobe
Facebook โ Python Programming Group for Discussions & Questions: https://www.facebook.com/groups/statisticsglobepython
LinkedIn โ Statistics Globe Page: https://www.linkedin.com/company/statisticsglobe/
LinkedIn โ R Programming Group for Discussions & Questions: https://www.linkedin.com/groups/12555223/
LinkedIn โ Python Programming Group for Discussions & Questions: https://www.linkedin.com/groups/12673534/
Twitter: https://twitter.com/JoachimSchork
Music by bensound.com
Python code of this video:
import pandas as pd # Load pandas library
data = pd.DataFrame({'values':[1, 2, 3, 1, 1, 1, 1, 2, 2], # Create example DataFrame
'groups':['a', 'a', 'a', 'a', 'b', 'b', 'c', 'c', 'c']})
print(data) # Print example DataFrame
count_unique = data['values'].nunique() # Apply unique function
print(count_unique) # Print count of unique values
# 3
Follow me on Social Media:
Facebook โ Statistics Globe Page: https://www.facebook.com/statisticsglobecom/
Facebook โ R Programming Group for Discussions & Questions: https://www.facebook.com/groups/statisticsglobe
Facebook โ Python Programming Group for Discussions & Questions: https://www.facebook.com/groups/statisticsglobepython
LinkedIn โ Statistics Globe Page: https://www.linkedin.com/company/statisticsglobe/
LinkedIn โ R Programming Group for Discussions & Questions: https://www.linkedin.com/groups/12555223/
LinkedIn โ Python Programming Group for Discussions & Questions: https://www.linkedin.com/groups/12673534/
Twitter: https://twitter.com/JoachimSchork
Music by bensound.com
Tags and Topics
Browse our collection to discover more content in these categories.
Video Information
Views
486
Likes
4
Duration
2:41
Published
Oct 26, 2022
Related Trending Topics
LIVE TRENDSRelated trending topics. Click any trend to explore more videos.