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-pandas-dataframe-index-list-numpy-array-python
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: https://www.facebook.com/statisticsglobecom/
Facebook – Group for Discussions & Questions: https://www.facebook.com/groups/statisticsglobe
LinkedIn – Statistics Globe Page: https://www.linkedin.com/company/statisticsglobe/
LinkedIn – Group for Discussions & Questions: https://www.linkedin.com/groups/12555223/
Twitter: https://twitter.com/JoachimSchork
Music by bensound.com