python读取csv文件的某一列或某几列

import csv
import pandas as pd

with open('D:\Data\新建文件夹\list3.2.csv','r') as csvfile:
reader = csv.reader(csvfile)
column1 = [row[1]for row in reader]
print(column1)


# 下面是按照列属性读取的
d = pd.read_csv('D:\Data\新建文件夹\list3.2.csv', usecols=['case', 'roi', 'eq. diam.','x loc.','y loc.','slice no.'])
print(d)

d = pd.read_csv('D:\Data\新建文件夹\list3.2.csv', usecols=['case', 'roi', 'eq. diam.','x loc.','y loc.','slice no.'],
nrows=10)
# 这是表示读取前10行
 
posted @ 2018-01-18 20:46  路在脚下丶  阅读(61941)  评论(0编辑  收藏  举报