Pandas Series Series.unique() Function

  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():



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()))


[ 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 Series.value_counts() Function
  • Pandas Series Series.nunique() Function
  • comments powered by Disqus