-1

I want an array of values from dataframe.keys() method. But it returns an Index object, that have the header values array as a member. But I want only that array, no other details.

header_values=features_dataframe.keys()
print(header_values)

Output

Index(['header1', 'header2', 'header3', 'header4', 'header5','Target'], dtype='object')

But I want

['header1', 'header2', 'header3', 'header4', 'header5','Target']

DevLoverUmar
  • 11,809
  • 11
  • 68
  • 98
  • I'm Sorry, but I'm not looking for Index, instead looking for headers! – DevLoverUmar Jul 12 '20 at 06:05
  • Hi, please take a deep breath. I've re-assessed this and changed the duplicate to [this one](https://stackoverflow.com/questions/19482970/get-list-from-pandas-dataframe-column-headers). [This answer](https://stackoverflow.com/a/55491499/4909087) I personally endorse. – cs95 Jul 12 '20 at 06:12
  • Okay :) but you can mark as duplicate without negative voting :p – DevLoverUmar Jul 12 '20 at 06:13
  • 1
    Voting is anonymous here, please don't assume that someone downvoted you as you could always be assuming incorrectly. In this case I did not touch the downvote button on your question. – cs95 Jul 12 '20 at 06:15

2 Answers2

3

Try it:

header_values = list(features_dataframe.keys())
print(header_values)
dimay
  • 2,768
  • 1
  • 13
  • 22
0

try:

list(features_dataframe.index)
r-beginners
  • 31,170
  • 3
  • 14
  • 32