Python | Панды Series.drop_duplicates ()
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.
Выход :
Now we will use Series.drop_duplicates() function to drop the duplicate values in the underlying data of the given series object.
# drop duplicatesresult = sr.drop_duplicates() # Print the resultprint(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 pdimport pandas as pd # Creating the Seriessr = pd.Series([11, 11, 8, 18, 65, 18, 32, 10, 5, 32, 32]) # Create the Indexindex_ = pd.date_range("2010-10-09", periods = 11, freq ="M") # set the indexsr.index = index_ # Print the seriesprint(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 duplicatesresult = sr.drop_duplicates() # Print the resultprint(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.
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.