csv转字典

2020-09-17 11:08:06 浏览数 (1)

代码语言:javascript复制
with open('filename','r') as csv_f:
    reader = csv.reader(csv_f)
    fieldnames = next(reader)
    csv_reader = csv.DictReader(f,fieldnames=fieldnames)
    for row in csv_reader:
        d = {}
        for k, v in row.items():
            d[k] = v
        print(d)
csv

0 人点赞