Hi, I am using .columns
attribute in pandas and I am getting INDEX
at the beginning, can someone please let me know that why INDEX
is mentioned at the beginning.
Asked
Active
Viewed 68 times
-1

Mrinal Roy
- 969
- 7
- 12

Rameez Khalil
- 3
- 1
-
1Because `.columns` returns a `pandas.core.indexes.base.Index` object, which happens to have `Index` in its string representation – DeepSpace Jul 17 '20 at 15:12
1 Answers
0
Answered before Index objects in pandas--why pd.columns returns index rather than list, official documentation .index.
Immutable ndarray implementing an ordered, sliceable set. The basic object storing axis labels for all pandas objects
If you are just expecting values then you've to go a little bit more. As .columns
returns an Index , .columns.values
returns an array and a helper function .tolist
returns a list of column names.
car_sales.columns.values.tolist()
You can use this car_sales.columns.tolist()
too but won't perform good in large dataframes.

Mrinal Roy
- 969
- 7
- 12