Python | Pandas Index.tolist ()

Опубликовано: 28 Марта, 2022

Python - отличный язык для анализа данных, в первую очередь из-за фантастической экосистемы пакетов Python, ориентированных на данные. Pandas - один из таких пакетов, который значительно упрощает импорт и анализ данных.

Pandas Index.tolist() function return a list of the values. These are each a scalar type, which is a Python scalar (for str, int, float) or a pandas scalar (for Timestamp/Timedelta/Interval/Period).

Syntax: Index.tolist()

Parameters : None

Returns : list

Example #1: Use Index.tolist() function to convert the index into a list.

# importing pandas as pd
import pandas as pd
  
# Creating the index
idx = pd.Index(["Harry", "Mike", "Arther", "Nick"],
                                  name ="Student")
  
# Print the Index
print(idx)

Выход :

Let’s convert the index into a List.

# convert the index into a list
idx.tolist()

Выход :

 
Example #2: Use Index.tolist() function to convert the index into a python list.

# importing pandas as pd
import pandas as pd
  
# Creating the index
idx = pd.Index(["2000-01-02", "2000-02-05", "2000-05-11",
                            "2001-02-11", "2005-11-12"])
  
# Print the Index
print(idx)

Выход :

Let’s convert the index into a List.

# convert the index into a list
idx.tolist()

Выход :

Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.

Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.