Convert pandas DataFrame to List in Python (3 Examples) | Extract Column & Row | Change All Elements

Опубликовано: 11 Март 2026
на канале: Statistics Globe
1,516
25

How to convert values in a pandas DataFrame to a list object in the Python programming language. More details: https://statisticsglobe.com/convert-p...
Python code of this video:

import pandas as pd # Import pandas

data = pd.DataFrame({'x1':range(10, 17), # Create pandas DataFrame
'x2':range(7, 0, - 1),
'x3':range(23, 30)})
print(data) # Print pandas DataFrame

list1 = data['x1'].tolist() # Select column
print(list1) # Print list
[10, 11, 12, 13, 14, 15, 16]

list2 = data.loc[[0]].values.tolist() # Select row
print(list2) # Print list
[[10, 7, 23]]

list3 = data.values.tolist() # Convert all values
print(list3) # Print list
[[10, 7, 23], [11, 6, 24], [12, 5, 25], [13, 4, 26], [14, 3, 27], [15, 2, 28], [16, 1, 29]]

Follow me on Social Media:
Facebook – Statistics Globe Page:   / statisticsglobecom  
Facebook – R Programming Group for Discussions & Questions:   / statisticsglobe  
Facebook – Python Programming Group for Discussions & Questions:   / statisticsglobepython  
LinkedIn – Statistics Globe Page:   / statisticsglobe  
LinkedIn – R Programming Group for Discussions & Questions:   / 12555223  
LinkedIn – Python Programming Group for Discussions & Questions:   / 12673534  
Twitter:   / joachimschork  

Music by bensound.com