Index.duplicated()
Pandas Index.duplicated()
Specifies duplicate index values. Duplicate values are denoted as True values in the resulting array. All duplicates can be specified, all but the first or all but the last occurrence of duplicates.
Syntax: Index.duplicated (keep = ’first’)
Parameters:
keep: {’first’, ’last’, False}, default ’first’
The value or values in a set of duplicates to mark as missing.
-" ’first’: Mark duplicates as True except for the first occurrence.
-" ’last’: Mark duplicates as True except for the last occurrence.
-" False: Mark all duplicates as True.
Returns: numpy.ndarray
Example # 1: Use Index.duplicated ()
to specify all duplicate values in the index except the first.
# import pandas as pd import pandas as pd # Create index idx = pd.Index ([ ’Labrador’ , ’Beagle’ , ’ Labrador’ , ’Lhasa’ , ’ Husky’ , ’Beagle’ ]) # Print index idx |
Output:
Let’s find out if whether the value present in the Index is duplicate or unique.
# Define duplicate values other than the first idx.duplicated (keep = ’first’ ) |
Output:
As we can see in the output, Index.duplicated ()
all occurrences of the duplicate value are True
except for the first occurrence.
Example # 2: Use Index.duplicated ()
to identify all duplicate values. here all duplicate values will be marked as True
# import pandas as pd import pandas as pd # Create index idx = pd.Index ([ 100 , 50 , 45 , 100 , 12 , 50 , None ]) # Print index idx |
Output:
Let’s define all duplicate values in the index.
Note: we have NaN
values in the index.
# Determine all duplicate value occurrences idx.duplicated (keep = False ) |
Output:
The function marked all duplicate values as True. He also considered a single occurrence of the NaN
value as unique and flagged it as false.
Shop
Learn programming in R: courses
$FREE
Best Python online courses for 2022
$FREE
Best laptop for Fortnite
$399+
Best laptop for Excel
$
Best laptop for Solidworks
$399+
Best laptop for Roblox
$399+
Best computer for crypto mining
$499+
Best laptop for Sims 4
$
Latest questions
PythonStackOverflow
Common xlabel/ylabel for matplotlib subplots
1947 answers
PythonStackOverflow
Check if one list is a subset of another in Python
1173 answers
PythonStackOverflow
How to specify multiple return types using type-hints
1002 answers
PythonStackOverflow
Printing words vertically in Python
909 answers
PythonStackOverflow
Python Extract words from a given string
798 answers
PythonStackOverflow
Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?
606 answers
PythonStackOverflow
Python os.path.join () method
384 answers
PythonStackOverflow
Flake8: Ignore specific warning for entire file
360 answers
Wiki
Python | How to copy data from one Excel sheet to another
Common xlabel/ylabel for matplotlib subplots
Check if one list is a subset of another in Python
How to specify multiple return types using type-hints
Printing words vertically in Python
Python Extract words from a given string
Cyclic redundancy check in Python
Finding mean, median, mode in Python without libraries
Python add suffix / add prefix to strings in a list
Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?
Python - Move item to the end of the list
Python - Print list vertically