Graphics Programs Reference
In-Depth Information
To drive the point home, here's the code to convert your CSV to JSON
format.
import csv
reader = csv.reader(open('wunder-data.txt', 'r'), delimiter=”,”)
print “{ observations: [“
rows_so_far = 0
for row in reader:
rows_so_far += 1
print '{'
print '“date”: ' + '“' + row[0] + '“, '
print '“temperature”: ' + row[1]
if rows_so_far < 365:
print “ },”
else:
print “ }”
print “] }”
Go through the lines to figure out what's going on, but again, it's the same
logic with different output. Here's what the JSON looks like if you run the
preceding code.
{
“observations”: [
{
“date”: “20090101”,
“temperature”: 26
},
{
“date”: “20090102”,
“temperature”: 34
},
...
]
}
This is still the same data, with date and temperature but in a different
format. Computers just love variety.
Search WWH ::




Custom Search