Python | Pandas MultiIndex.names
Python - отличный язык для анализа данных, в первую очередь из-за фантастической экосистемы пакетов Python, ориентированных на данные. Pandas - один из таких пакетов, который значительно упрощает импорт и анализ данных.
Pandas MultiIndex.names attribute returns the names of levels in the MultiIndex.
Syntax: MultiIndex.names
Example #1: Use MultiIndex.names attribute to find the names of the levels in the MultiIndex.
# importing pandas as pdimport pandas as pd # Creating the arrayarray = [[1, 2, 3], ["Sharon", "Nick", "Bailey"]] # Print the arrayprint(array) |
Выход :
Now let’s create the MultiIndex using this array
# Creating the MultiIndexmidx = pd.MultiIndex.from_arrays(array, names =("Number", "Names")) # Print the MultiIndexprint(midx) |
Выход :
Now we will find the names of all the levels in the MultiIndex.
# Print the names of the level in MultiIndexmidx.names |
Output :
As we can see in the output, midx has two levels and the name of the levels are ‘Number’ and ‘Names’.
Example #2: Use MultiIndex.names attribute to find the names of the levels in the given MultiIndex.
# importing pandas as pdimport pandas as pd # Creating the arrayarray =[[1, 2, 3], ["Sharon", "Nick", "Bailey"], ["Doctor", "Scientist", "Physicist"]] # Print the arrayprint(array) |
Выход :
Now let’s create the MultiIndex using this array
# Creating the MultiIndexmidx = pd.MultiIndex.from_arrays(array, names =("Ranking", "Names", "Profession")) # Print the MultiIndexprint(midx) |
Выход :
Now we will find the names of all the levels in the MultiIndex.
# Print the names of the level in MultiIndexmidx.names |
Выход :
Как видно из выходных данных, midx имеет три уровня, и названия уровней - «Число», «Имена» и «Профессия».
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.