Read specific columns from a csv file with csv module?

后端 未结 12 1168
闹比i
闹比i 2020-11-22 10:06

I\'m trying to parse through a csv file and extract the data from only specific columns.

Example csv:

ID | N         


        
12条回答
  •  面向向阳花
    2020-11-22 11:07

    I think there is an easier way

    import pandas as pd
    
    dataset = pd.read_csv('table1.csv')
    ftCol = dataset.iloc[:, 0].values
    

    So in here iloc[:, 0], : means all values, 0 means the position of the column. in the example below ID will be selected

    ID | Name | Address | City | State | Zip | Phone | OPEID | IPEDS |
    10 | C... | 130 W.. | Mo.. | AL... | 3.. | 334.. | 01023 | 10063 |
    

提交回复
热议问题