Convert pandas DataFrame Index to List & NumPy Array in Python (2 Examples) | Extract Data Indices

Published: 11 April 2022
on channel: Statistics Globe
908
22

How to get the indices of a pandas DataFrame as a list or a NumPy array in the Python programming language. More details: https://statisticsglobe.com/convert-p...
R code of this video:

import pandas as pd # Import pandas library

data = pd.DataFrame({"x1":range(1, 10), # Create pandas DataFrame
"x2":["a", "b", "c", "d", "e", "d", "c", "b", "a"],
"x3":range(10, 1, - 1)})
print(data) # Print pandas DataFrame

data_index1 = data.index.tolist() # Extract as list object
print(data_index1) # Print index as list

data_index2 = data.index.values # Extract as NumPy array
print(data_index2) # Print index as NumPy array

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

Music by bensound.com


On this page of the site you can watch the video online Convert pandas DataFrame Index to List & NumPy Array in Python (2 Examples) | Extract Data Indices with a duration of hours minute second in good quality, which was uploaded by the user Statistics Globe 11 April 2022, share the link with friends and acquaintances, this video has already been watched 908 times on youtube and it was liked by 22 viewers. Enjoy your viewing!