Pandas functions
Pandas Unique β pd.Series.unique()
Pandas unique values extraction
Have you ever wondered what the distinct (unique) values are within your pandas DataFrame column? That is where Pandas Unique comes into play.
I have two main uses for finding distinct values:
- When Iβm trying to visually see what values lie within a pandas column. I will often go between .unique() and .value_counts() to get a feel for my data.
- When Iβm trying to iterate through a DataFrame. I will loop through the unique values of a column, then filter a DataFrame by itβs unique value. Check out the examples below for an instance of this.
Pseudo Code: Look at a Pandas Series, then return only the distinct values. No showing multiple values allowed.
Pandas Unique
.unique() Parameters
None! .unique() does not take any values. Simply pass your list of values or a series and the distinct values will be returned to you.
One thing to note: You can call pd.unique() and pass a list of values, or you can call pd.Series.unique() and get the distinct values right on your series.
Now the fun part, letβs take a look at a code sample