pandas
  1. pandas-seriesunique

Series.unique() - Pandas Series

The unique() method in Pandas Series is used to get a list of unique values in a Series. It returns a numpy array, which contains unique values from the Series in the order in which they appear.

Syntax

Series.unique()

Example

import pandas as pd

data = pd.Series([4, 2, 1, 4, 3, 2, 1, 3, 3])

unique_data = data.unique()

print(unique_data)

Output

[4 2 1 3]

Explanation

In the above example, we have created a Pandas Series object with 9 integer elements. We call the unique() method on this Series to get unique values from the Series. The method returns a numpy array of unique values, which are [4 2 1 3], in the order of their appearance in the Series.

Use

The unique() method of Pandas Series is used to get unique values from a Series. This method is useful for data analysis, where we often need to perform various operations on unique values from a dataset.

Important Points

  • The unique() method returns a numpy array of unique values in the order of their appearance.
  • The unique() method doesn't modify the original Series.
  • The unique() method can be used only on Pandas Series objects and not on DataFrames.

Summary

The unique() method of Pandas Series is a useful method to get unique values from a Series. It returns a numpy array of unique values, which are in the order of their appearance in the Series. This method is helpful in data analysis and performing various operations on unique values from a dataset.

Published on: