पहली घटना को छोड़कर डुप्लीकेट इंडेक्स मानों को इंगित करने के लिए, 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 first occurrence...\n", index.duplicated(keep='first')) उदाहरण
निम्नलिखित कोड है -
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 first occurrence
# Set the "keep" parameter as "first"
print("\nIndicating duplicate values except the first occurrence...\n", index.duplicated(keep='first')) आउटपुट
यह निम्नलिखित कोड उत्पन्न करेगा -
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 first occurrence... [False False False False True]