Add VT2-examples: all 6 chapters of 'Visualize This' (110 files) — data scraping, ETL, trends, categorical, multivariate, spatial, distribution analysis
This commit is contained in:
1 parent
088771a9cf
commit
b42b866a8c
110 files changed
+400895
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import csv
|
||||
|
||||
fields = None
|
||||
with open('income-scraped.csv') as csvfile:
|
||||
|
||||
reader = csv.reader(csvfile, delimiter=",")
|
||||
for row in reader:
|
||||
|
||||
# Save header variables
|
||||
if fields == None:
|
||||
fields = row
|
||||
|
||||
else:
|
||||
|
||||
# Start JSON string
|
||||
if row[0] == "1":
|
||||
famunit = '['
|
||||
else:
|
||||
famunit = ''
|
||||
|
||||
# Add family unit
|
||||
famunit += '{'
|
||||
famunit += '"' + fields[0] + '":' + row[0] + ',' # famindex
|
||||
famunit += '"' + fields[1] + '":' + row[1] + ',' # AGE
|
||||
famunit += '"' + fields[2] + '":' + row[2] # FTOTINC
|
||||
famunit += '}'
|
||||
|
||||
# Close set if at end
|
||||
if (row[0] == "200"):
|
||||
famunit += ']'
|
||||
else:
|
||||
famunit += ','
|
||||
|
||||
# Print family unit
|
||||
print(famunit)
|
||||
Reference in new issue
Block a user