API · Pandas
Pandas Series Series.unique() Function
The Pandas Series.unique method returns the unique values in the Python Pandas Series. The values are ordered by the appearance.
On this page
Python Pandas Series.unique method returns the unique values in the Python Pandas Series. The values are ordered by the appearance.
Syntax of pandas.Series.unique():
Series.unique()
Return
It returns a NumPy array with the unique values in the Pandas Series, in the order of appearance.
Example Codes: Series.unique() Method
import pandas as pd
import numpy as np
ser = pd.Series([1, 2, 3, np.nan, 3, 4, np.nan],
name = 'No.')
print(ser.unique(), type(ser.unique()))
Output:
[ 1. 2. 3. nan 4.] <class 'numpy.ndarray'>
A NumPy array is returned with the unique values in the caller Pandas Series.
NaN is also treated as a unique value in Python Pandas Series.unique() method.