- 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
Python Pandas - Indicate duplicate index values
To indicate duplicate index values, use the index.duplicated() method.
At first, import the required libraries −
import pandas as pd
Creating the indexwith some duplicates −
index = pd.Index(['Car','Bike','Airplane','Ship','Airplane'])
Display the index −
print("Pandas Index with duplicates...\n",index)
Indicate duplicate index values as True, rest False. By default, it keeps the first occurrence of the duplicate value unmarked −
print("\nIndicating duplicate values...\n", index.duplicated())
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 duplicate index values as True, rest False # By default it keeps the first occurrence of the duplicate value unmarked print("\nIndicating duplicate values...\n", index.duplicated())
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 duplicate values... [False False False False True]
Advertisements