Open In App

Python | Pandas Series.duplicated()

Improve
Improve
Like Article
Like
Save
Share
Report

Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer and label-based indexing and provides a host of methods for performing operations involving the index.

Pandas Series.duplicated() function indicate duplicate Series values. The duplicated values are indicated as True values in the resulting Series. Either all duplicates, all except the first or all except the last occurrence of duplicates can be indicated.

Syntax: Series.duplicated(keep=’first’)

Parameter :
keep : {‘first’, ‘last’, False}, default ‘first’

Returns : pandas.core.series.Series

Example #1: Use Series.duplicated() function to find the duplicate values in the given series object.




# importing pandas as pd
import pandas as pd
  
# Creating the Series
sr = pd.Series([80, 25, 3, 25, 24, 6])
  
# Create the Index
index_ = ['Coca Cola', 'Sprite', 'Coke', 'Fanta', 'Dew', 'ThumbsUp']
  
# set the index
sr.index = index_
  
# Print the series
print(sr)


Output :

Now we will use Series.duplicated() function to find the duplicate values in the underlying data of the given series object.




# detect duplicates
result = sr.duplicated()
  
# Print the result
print(result)


Output :

As we can see in the output, the Series.duplicated() function has successfully detected the duplicated values in the given series object. False indicates that the corresponding value is unique whereas, True indicates that the corresponding value was a duplicated value in the given series object.
 
Example #2 : Use Series.duplicated() function to find the duplicate values in the given series object.




# importing pandas as pd
import pandas as pd
  
# Creating the Series
sr = pd.Series([11, 11, 8, 18, 65, 18, 32, 10, 5, 32, 32])
  
# Create the Index
index_ = pd.date_range('2010-10-09', periods = 11, freq ='M')
  
# set the index
sr.index = index_
  
# Print the series
print(sr)


Output :

Now we will use Series.duplicated() function to find the duplicate values in the underlying data of the given series object.




# detect duplicates
result = sr.duplicated()
  
# Print the result
print(result)


Output :

As we can see in the output, the Series.duplicated() function has successfully detected the duplicated values in the given series object. False indicates that the corresponding value is unique whereas, True indicates that the corresponding value was a duplicated value in the given series object.



Last Updated : 13 Feb, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads