Open In App

Python | Pandas Series.drop_duplicates()

Last Updated : 13 Feb, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

Pandas Series.drop_duplicates() function returns a series object with duplicate values removed from the given series object.

Syntax: Series.drop_duplicates(keep=’first’, inplace=False)

Parameter :
keep : {‘first’, ‘last’, False}, default ‘first’
inplace : If True, performs operation inplace and returns None.

Returns : deduplicated : Series

Example #1: Use Series.drop_duplicates() function to drop the duplicate values from 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.drop_duplicates() function to drop the duplicate values in the underlying data of the given series object.




# drop duplicates
result = sr.drop_duplicates()
  
# Print the result
print(result)


Output :

As we can see in the output, the Series.drop_duplicates() function has successfully dropped the duplicate entries from the given series object.
 
Example #2 : Use Series.drop_duplicates() function to drop the duplicate values from 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.drop_duplicates() function to drop the duplicate values in the underlying data of the given series object.




# drop duplicates
result = sr.drop_duplicates()
  
# Print the result
print(result)


Output :

As we can see in the output, the Series.drop_duplicates() function has successfully dropped the duplicate entries from the given series object.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads