Javatpoint Logo
Javatpoint Logo

Pandas Series.unique()

While working with the DataFrame in Pandas, you need to find the unique elements present in the column. For doing this, we have to use the unique() method to extract the unique values from the columns. The Pandas library in Python can easily help us to find unique data.

The unique values present in the columns are returned in order of its occurrence. This does not sort the order of its appearance. In addition, this method is based on the hash-table.

It is significantly faster than numpy.unique() method and also includes null values.

Syntax:

Parameters:

values: It refers to a 1d array-like object that consists of an array value.

Returns:

This method returns a numpy.ndarray or ExtensionArray object and can be:

  • index: Returns when user passes index as an input.
  • Categorical: Returns when user passes a Categorical dtype as an input.
  • ndarray: Returns when user passes a ndarray/Series as an input.

Example 1:

Output:

array(['2016-01-01T00:00:00.000000000'], dtype='datetime64[ns]')

Example 2: The below example extracts the unique timestamp from the Index:

Output:

DatetimeIndex(['2016-01-01 00:00:00-05:00'], dtype='datetime64[ns, US/Eastern]', freq=None)





Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA