題目:
1、將提供的 test.csv 文件,具體內容如下:
intend爲json縮進量,用來實現換行
test.csv數據:
城市 | 環比 | 同比 | 定基 |
北京 | 101.5 | 120.7 | 121.4 |
上海 | 101.2 | 127.3 | 127.8 |
廣州 | 101.3 | 119.4 | 120 |
深圳 | 102 | 140.9 | 145.5 |
瀋陽 | 100.1 | 101.4 | 101.6 |
import json
import jieba
article = open('test.csv', 'r').read()
listans=[]
words=article.split('\n')
length=len(words)
for i in range(length):
words[i]=words[i].split(',')
dictionary=words[0]
for i in range(1,length-1):
dictionary_seq=words[i]
dic=dict(zip(dictionary,dictionary_seq))
listans.append(dic)
out=json.dumps(listans,ensure_ascii=False,indent=4)
print('''"本書作者:{}"'''.format(out))