Examples

In [1]:
import numpy as np
import pandas as pd
In [2]:
pd.Series([2, 4, 3, 3], name='P').unique()
Out[2]:
array([2, 4, 3], dtype=int64)
In [3]:
pd.Series([pd.Timestamp('2019-01-01') for _ in range(3)]).unique()
Out[3]:
array(['2019-01-01T00:00:00.000000000'], dtype='datetime64[ns]')
In [4]:
pd.Series([pd.Timestamp('2019-01-01', tz='US/Eastern')
           for _ in range(3)]).unique()
Out[4]:
<DatetimeArray>
['2019-01-01 00:00:00-05:00']
Length: 1, dtype: datetime64[ns, US/Eastern]

An unordered Categorical will return categories in the order of appearance.

In [5]:
pd.Series(pd.Categorical(list('qppqr'))).unique()
Out[5]:
[q, p, r]
Categories (3, object): [q, p, r]

An ordered Categorical preserves the category ordering.

In [6]:
pd.Series(pd.Categorical(list('qppqr'), categories=list('pqr'),
                         ordered=True)).unique()
Out[6]:
[q, p, r]
Categories (3, object): [p < q < r]