पिछली बार के अलावा डुप्लीकेट इंडेक्स मानों को इंगित करने के लिए, index.duplicated() . का उपयोग करें . रखें . का उपयोग करें मान अंतिम . के साथ पैरामीटर ।
सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -
import pandas as pd
कुछ डुप्लीकेट के साथ इंडेक्स बनाना-
index = pd.Index(['Car','Bike','Airplane','Ship','Airplane'])
सूचकांक प्रदर्शित करें -
print("Pandas Index with duplicates...\n",index) अंतिम घटना को छोड़कर, डुप्लिकेट इंडेक्स मानों को सही के रूप में इंगित करें। "कीप" पैरामीटर को "अंतिम" के रूप में सेट करें -
print("\nIndicating duplicate values except the last occurrence...\n", index.duplicated(keep='last')) उदाहरण
निम्नलिखित कोड है -
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, except the last occurrence
# Set the "keep" parameter as "last"
print("\nIndicating duplicate values except the last occurrence...\n", index.duplicated(keep='last')) आउटपुट
यह निम्नलिखित कोड उत्पन्न करेगा -
Pandas Index with duplicates... Index(['Car', 'Bike', 'Airplane', 'Ship', 'Airplane'], dtype='object') The dtype object... object Get the dimensions... 1 Indicating duplicate values except the last occurrence... [False False True False False]