सभी डुप्लिकेट इंडेक्स मानों को True के रूप में दर्शाने के लिए, index.duplicated() का उपयोग करें। keep पैरामीटर का उपयोग False मान के साथ करें।
सबसे पहले, आवश्यक लाइब्रेरी इंपोर्ट करें:
import pandas as pd
कुछ डुप्लिकेट्स के साथ इंडेक्स बनाएं:
index = pd.Index(['Car','Bike','Airplane','Ship','Airplane'])
इंडेक्स प्रदर्शित करें:
print("Pandas Index with duplicates...\n", index)
सभी डुप्लिकेट इंडेक्स मानों को True के रूप में दर्शाएं। "keep" पैरामीटर को "False" पर सेट करें:
print("\nIndicating all duplicate index values True...\n", index.duplicated(keep=False))
उदाहरण
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))
आउटपुट
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]