Pandas Series Series.unique() Function

Suraj Joshi Jan 30, 2023
  1. Syntax of pandas.Series.unique():
  2. Example Codes: Series.unique() Method
Pandas Series Series.unique() Function

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.

Author: Suraj Joshi
Suraj Joshi avatar Suraj Joshi avatar

Suraj Joshi is a backend software engineer at Matrice.ai.

LinkedIn

Related Article - Pandas Series