如下所示:
1
2
3
4
5
6
7
8
9
10
11
|
import csv
with open ( "csv.csv" , 'r' ,encoding = "utf-8" ) as f:
reader = csv.reader(f)
# print(fieldnames)
csv_reader = csv.dictreader(f,fieldnames = fieldnames) #self._fieldnames = fieldnames # list of keys for the dict 以list的形式存放键名
for row in csv_reader:
d = {}
for k,v in row.items():
d[k] = v
print (d)
|
以上这篇python3 cvs将数据读取为字典的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/dance117/article/details/80950412