14

I am using pandas to read a heavy csv file as below

import pandas
csv_file_path = "/Users/import.csv"
csv_data = pandas.read_csv(csv_file_path, names=data_mapping_field_values)

When i use csv_data.columns, i got below

Index([u'Domain', u'RefSubNets', u'RefIPs', u'IDN_Domain'], dtype='object')

But i want only a list of columns like below

[u'Domain', u'RefSubNets', u'RefIPs', u'IDN_Domain']

How can we access only columns of a csv file as a list using pandas?

Shiva Krishna Bavandla
  • 25,548
  • 75
  • 193
  • 313
  • 7
    You can use `tolist()`. `csv_data.columns.tolist()` – Psidom Jan 20 '17 at 16:00
  • 1
    By the way, if it is not for display purposes, most of the time it is better to leave them as indices. You can still iterate, slice and do all the things that you can do with the lists but you can also use index methods. – ayhan Jan 20 '17 at 16:22

0 Answers0