python获取csv文本的某行或某列数据

 1 #coding = 'utf-8'
 2 
 3 import csv
 4 
 5 # 使用list,只能读取列,而且是全文读取,csv.reader会自动把CSV内容生成数组
 6 '''
 7 df = csv.reader(open('F:\c_database\c2015.csv'))
 8 for data in df:
 9     print (data[3])
10 '''
11 
12 #如果要读取某行,必须将CSV内容生成 DICT字典(2维)
13 with open('F:\c_database\c2015.csv','r') as csvfile:
14         reader = csv.DictReader(csvfile)
15         for row in reader:
16                 if row['日期']  ==  '20150105':
17                     print (row)

 

posted on 2019-07-18 13:25  sub2020  阅读(2797)  评论(0编辑  收藏  举报

导航