Pandas Series Series.unique() Function
Suraj Joshi
Jan 30, 2023
Pandas
Pandas Series
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.
Enjoying our tutorials? Subscribe to DelftStack on YouTube to support us in creating more high-quality video guides. Subscribe
Author: Suraj Joshi
Suraj Joshi is a backend software engineer at Matrice.ai.
LinkedIn