📜  Python|熊猫系列.unique()(1)

📅  最后修改于: 2023-12-03 15:04:27.587000             🧑  作者: Mango

Python Pandas Series - unique()

Introduction

In this article, we will explore the unique() function in the Pandas Series of the Python programming language. Pandas is a popular library for data manipulation and analysis in Python, and the Series is one of its core data structures. The unique() function is used to obtain an array of unique values present in a Series object.

Syntax

The syntax of the unique() function is as follows:

Series.unique()
Parameters

The unique() function does not take any parameters.

Return Value

The unique() function returns an array of unique values present in the Series object. The data type of the returned array depends on the data type of the elements in the Series.

Example

Let's consider a simple example to understand how the unique() function works:

import pandas as pd

# Create a Series object
my_series = pd.Series([1, 2, 3, 1, 2, 4, 5, 1, 3, 5])

# Get the unique values
unique_values = my_series.unique()

print(unique_values)

Output:

[1, 2, 3, 4, 5]

In the above example, we first create a Pandas Series object called my_series, which contains some duplicate values. Then, the unique() function is called on my_series to obtain an array of unique values. Finally, we print the unique values, which are [1, 2, 3, 4, 5].

Conclusion

The unique() function in the Pandas Series allows us to find the unique values present in a Series object. It is a useful tool for data analysis and manipulation in Python.