
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Pandas - Check if the index has unique values
To check if the index has unique values, use the index.is_unique.
At first, import the required libraries −
import pandas as pd
Let us create the index −
index = pd.Index([50, 40, 30, 20, 10])
Display the index −
print("Pandas Index...\n",index)
Check if the index is having unique values −
print("\nIs the Pandas index having unique values?\n",index.is_unique)
Example
Following is the code −
import pandas as pd # Creating the index index = pd.Index([50, 40, 30, 20, 10]) # Display the index print("Pandas Index...\n",index) # Return an array representing the data in the Index print("\nArray...\n",index.values) # Check if the index is having unique values print("\nIs the Pandas index having unique values?\n",index.is_unique)
Output
This will produce the following code −
Pandas Index... Int64Index([50, 40, 30, 20, 10], dtype='int64') Array... [50 40 30 20 10] Is the Pandas index having unique values? True
- Related Articles
- Python Pandas - Check if the index has duplicate values
- Python Pandas - Check if the index has NaNs
- Python Pandas - Return unique values in the index
- Python Pandas - Check if the Pandas Index holds Interval objects
- Python - Check if the Pandas Index holds categorical data
- Python Pandas - Check if the IntervalIndex has overlapping intervals
- Python - Check if the Pandas Index only consists of booleans
- Python - Check if the Pandas Index is a floating type
- Python - Check if the Pandas Index only consists of integers
- Python - Check if the Pandas Index is of the object dtype
- Python Pandas - Return a Series containing counts of unique values from Index object
- Python - Check if the Pandas Index only consists of numeric data
- Python Pandas - Check if the index is empty with 0 elements
- Python Pandas - Indicate duplicate index values
- Python Pandas - Return a Series containing counts of unique values from Index object considering NaN values as well

Advertisements