我需要使用python 3.6将csv文件转换为JSON文件。尽可能使用熊猫。格式是特定的,当前我的代码无法正确输出。
b0:7f:b9:bc:f0:e0,-54
b0:7f:b9:bc:f0:40,-62
b0:7f:b9:bc:f0:e1,-57
b0:7f:b9:bc:f0:e2,-56
b8:62:1f:e4:d9:34,-61
b0:7f:b9:bc:f0:42,-62
34:a8:4e:fd:60:84,-65
b8:62:1f:e4:d9:33,-61
34:a8:4e:fd:60:83,-65
4c:5e:0c:71:46:55,-82
import csv
import json
f = open( 'mycsvfile.csv', 'r' )
reader = csv.DictReader( f)
out = json.dumps( [ row for row in reader ] )
print (out)
fo = open('myoutputfile.json','w')
fo.write(out)
fo.close()
"wifi":{
"b0:7f:b9:bc:f0:e0":-54,
"b0:7f:b9:bc:f0:40":-62,
"b0:7f:b9:bc:f0:e1":-57,
"b0:7f:b9:bc:f0:e2":-56,
"b8:62:1f:e4:d9:34":-61,
"b0:7f:b9:bc:f0:42":-62,
"34:a8:4e:fd:60:84":-65,
...
}