
- 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 - Indicate all duplicate index values as True
To indicate all duplicate index values as True, use the index.duplicated(). Use the keep parameter with the value False.
At first, import the required libraries −
import pandas as pd
Creating the index with some duplicates −
index = pd.Index(['Car','Bike','Airplane','Ship','Airplane'])
Display the index −
print("Pandas Index with duplicates...\n",index)
Indicate all duplicate index values as True. Set the "keep" parameter as "False" −
print("\nIndicating all duplicate index values True...\n", index.duplicated(keep=False))
Example
Following is the code −
import pandas as pd # Creating the index with some duplicates index = pd.Index(['Car','Bike','Airplane','Ship','Airplane']) # Display the index print("Pandas Index with duplicates...\n",index) # Return the dtype of the data print("\nThe dtype object...\n",index.dtype) # get the dimensions of the data print("\nGet the dimensions...\n",index.ndim) # Indicate all duplicate index values as True # Set the "keep" parameter as "False" print("\nIndicating all duplicate index values True...\n", index.duplicated(keep=False))
Output
This will produce the following code −
Pandas Index with duplicates... Index(['Car', 'Bike', 'Airplane', 'Ship', 'Airplane'], dtype='object') The dtype object... object Get the dimensions... 1 Indicating all duplicate index values True... [False False True False True]
- Related Articles
- Python Pandas - Indicate duplicate index values
- Python Pandas - Indicate duplicate index values except for the first occurrence
- Python Pandas - Indicate duplicate index values except for the last occurrence
- Python Pandas - Return Index with duplicate values removed
- Python Pandas - Check if the index has duplicate values
- Python Pandas - Return Index with duplicate values completely removed
- Python Pandas - Return whether all elements in the index are True
- Python Pandas - Return Index with duplicate values removed except the first occurrence
- Python Pandas - Return Index with duplicate values removed keeping the last occurrence
- Python - Remove duplicate values from a Pandas DataFrame
- Python Pandas - Return Index without NaN values
- Python Pandas - Return unique values in the index
- Python Pandas - Return whether any element in the index is True
- Python Pandas - Return a Series containing counts of unique values from Index object considering NaN values as well
- Python Pandas - Return a list of the Index values

Advertisements