Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

I'm probably using poor search terms when trying to find this answer. Right now, before indexing a DataFrame, I'm getting a list of values in a column this way...

 list = list(df['column']) 

...then I'll set_index on the column. This seems like a wasted step. When trying the above on an index, I get a key error.

How can I grab the values in an index (both single and multi) and put them in a list or a list of tuples?

1 Answer

0 votes
by (41.4k points)

To get the index values as a list/list of tuples for Index/MultiIndex use the below line of code:

df.index.values.tolist(

If you want to learn more about Pandas then visit this Python Course Designed By Experts.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...