- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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?n
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”.
Example 1
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)
Explanation
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.
Output
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.
Example 2
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)
Explanation
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.
Output
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.
- Related Articles
- How to check whether the Pandas series is having Nan values or not?
- Program to check occurrences of every value is unique or not in Python
- How To Check Whether a Number is a Unique Number or Not in Java?
- How to check the data type of a pandas series?
- 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?
- Program to check whether each node value except leaves is sum of its children value or not in Python
- How to check whether a value is a safe integer or not in JavaScript?
- Python Pandas - Check whether the DateOffset value has been normalized or not
- How to check if the value is primitive or not in JavaScript?
- How to Get the Position of Max Value of a pandas Series?
- How to Get the Position of Minimum Value of a pandas Series?
- How to calculate the frequency of each item in a Pandas series?
- JavaScript: How to check whether an array includes a particular value or not?
- A Program to check if strings are rotations of each other or not?
