- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to check each value of a pandas series is unique or not?
The pandas.Series constructor have an attribute called is_unique. which is used to check whether the data present in the pandas series object is unique or not. As we know, the pandas series object is a single-dimensional data structure, which stores any type of data with label representation.
By using the “is_unque” attribute we can check if all data present in the series object holds unique values or not. And it returns a boolean value as an output.
It returns “True” if the data present in the given series object is unique, otherwise, it will return “False”.
import pandas as pd # creating pandas Series with date sequence series = pd.Series(['2021-01-01','2021-01-02','2021-01-02', '2021-01-03','2021-01-05']) print(series) # apply is_unique property print("Is Unique: ", series.is_unique)
Here, we have initialized a Series with a list of data sequences of length 5. Then we applied the is_unique property to verify if the data present in the given series object is unique or not.
0 2021-01-01 1 2021-01-02 2 2021-01-02 3 2021-01-03 4 2021-01-05 dtype: object Is Unique: False
In the above output block, we can see the given series object, and also the boolean value “False”. The output boolean value “False” is the returned from the canis_unique attribute, which means that the data present in the given series is having duplicate data.
import pandas as pd # creating pandas Series with list of integers series = pd.Series([1,2,3,4,5,6]) print(series) # apply is_unique property print("Is Unique: ", series.is_unique)
Let’s take another example for checking if the values in a series object is unique or not. Here, we have created a series object with a python list of integers. And that applied the is_unique attribute to the given pandas series object.
0 1 1 2 2 3 3 4 4 5 5 6 dtype: int64 Is Unique: True
We can see both the series object and also the output from the is_unique attribute is displayed in the above output block. We got the boolean value “True” as a result of the is_anique attribute, so we can say that the data in the given series object is having all unique values.
- Program to check occurrences of every value is unique or not in Python
- How to check whether the Pandas series is having Nan values or not?
- Program to check whether each node value except leaves is sum of its children value or not in Python
- How to check the data present in a Series object is monotonically increasing or not?
- How to check the data present in a Series object is monotonically decreasing or not?
- A Program to check if strings are rotations of each other or not?
- How to check the data type of a pandas series?
- Python Pandas - Check whether the DateOffset value has been normalized or not
- How to calculate the frequency of each item in a Pandas series?
- Check whether the entered value is a digit or not in Java
- Check whether the entered value is a letter or not in Java
- How to Get the Position of Max Value of a pandas Series?
- How to Get the Position of Minimum Value of a pandas Series?
- Program to check strings are rotation of each other or not in Python