tolist(): List from Pandas DataFrame

We can create one list from DataFrame
import pandas as pd 
my_dict={'NAME':['Ravi','Raju','Alex','Ron','King','Jack'],
         'ID':[1,2,3,4,5,6],
         'MATH':[80,40,70,70,60,30],
         'ENGLISH':[80,70,40,50,60,30]}
df = pd.DataFrame(data=my_dict) # dataframe 
my_list=df.values.tolist() # creates a list 
print(type(my_list)) # <class 'list'>
This will hold all our dataframe data ( but without column names )
print(my_list)
Output
[['Ravi', 1, 80, 80], ['Raju', 2, 40, 70], 
['Alex', 3, 70, 40], ['Ron', 4, 70, 50], 
['King', 5, 60, 60], ['Jack', 6, 30, 30]]

Adding column names to the list.

We used list insert method to add the column names.
import pandas as pd 
my_dict={'NAME':['Ravi','Raju','Alex','Ron','King','Jack'],
         'ID':[1,2,3,4,5,6],
         'MATH':[80,40,70,70,60,30],
         'ENGLISH':[80,70,40,50,60,30]}
df = pd.DataFrame(data=my_dict) # dataframe 
my_list=df.values.tolist() # creates a list 
my_list.insert(0,df.columns) # adding column names to list
print(my_list)
Output
[Index(['NAME', 'ID', 'MATH', 'ENGLISH'], dtype='object'), 
['Ravi', 1, 80, 80], ['Raju', 2, 40, 70], 
['Alex', 3, 70, 40], ['Ron', 4, 70, 50], 
['King', 5, 60, 60], ['Jack', 6, 30, 30]]

Using DataFrame column to create a list

We can create a DataFrame by using read_excel() function. From the DataFrame we can use one column data to create one list.
import pandas as pd
df=pd.read_excel("D:\\my_data\\tk-colours.xlsx") # Create DataFrame.
my_list=df['Name'].values.tolist() # data source 

Using DataFrame index to create list

Use any one
my_list=df.index.values.tolist()
my_list = list(df.index)
my_list = list(df.index.values)
tolist() is used to create LIST from DataFrame to create PDF table
Pandas DataFrame describe() head() to_string() rename()
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer