Pandas Series Series.unique() Function

Pandas Series Series.unique() Function

Suraj Joshi Jul-18, 2021 May-30, 2020 Pandas Pandas Series
  1. Syntax of pandas.Series.unique():
  2. Example Codes: Series.unique() Method

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.

Related Article - Pandas Series

  • Pandas Series.head() Function
  • Pandas Series.to_frame() Function
  • Pandas Series.tolist() Function
  • Pandas Series Series.map() Function
  • Pandas Series Series.nunique() Function