Reading column names alone in a csv file

前端 未结 9 2311
不思量自难忘°
不思量自难忘° 2020-12-23 18:58

I have a csv file with the following columns:

id,name,age,sex

Followed by a lot of values for the above columns. I am trying to read the column names alone and

9条回答
  •  佛祖请我去吃肉
    2020-12-23 19:27

    I am just mentioning how to get all the column names from a csv file. I am using pandas library.

    First we read the file.

    import pandas as pd
    file = pd.read_csv('details.csv')
    

    Then, in order to just get all the column names as a list from input file use:-

    columns = list(file.head(0))
    

提交回复
热议问题