Python | Панды Index.get_duplicates ()
Python - отличный язык для анализа данных, в первую очередь из-за фантастической экосистемы пакетов Python, ориентированных на данные. Pandas - один из таких пакетов, который значительно упрощает импорт и анализ данных.
Pandas Index.get_duplicates() function extract duplicated index elements. This function returns a sorted list of index elements which appear more than once in the Index.
Syntax: Index.get_duplicates()
Returns : List of duplicated indexes.
Example #1: Use Index.get_duplicates() function to find all the duplicate values in the Index.
# importing pandas as pdimport pandas as pd # Creating the Indexidx = pd.Index(["Labrador", "Beagle", "Labrador", "Lhasa", "Husky", "Beagle"]) # Print the Indexidx |
Выход :
let’s find out all the duplicate values in the Index.
# print the duplicated values.idx.get_duplicates() |
Output :
As we can see in the output, the Index.get_duplicates() function has returned all the values which are having more than one occurrence in the Index.
Example #2: Use Index.get_duplicates() function to find all the duplicate in the Index. The Index also contains NaN values.
# importing pandas as pdimport pandas as pd # Creating the Indexidx = pd.Index(["Labrador", "Beagle", None, "Labrador", "Lhasa", "Husky", "Beagle", None, "Koala"]) # Print the Indexidx |
Output :
As we can see in the output we are having some missing values. Lets see how the Index.get_duplicates() function treats them.
# print the duplicate values in Indexidx.get_duplicates() |
Выход :
Наличие пропущенных значений более одного раза рассматривается как дублирование.
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.