Skip to content

Instantly share code, notes, and snippets.

@cavedave
Created November 14, 2013 22:53
Show Gist options
  • Save cavedave/7475784 to your computer and use it in GitHub Desktop.
Save cavedave/7475784 to your computer and use it in GitHub Desktop.
Python code to colourize each country based on how much grin it produces
import csv
# Read in wheat production -----
wheat = {}
reader = csv.reader(open('psd_grains_pulses.csv'), delimiter=",")
#first line is the header
next(reader, None)
for row in reader:
try:
#find rows witht he wheat code
if int(row[0]) == 410000:
#find the row about production
if row[8]== "Production":
#find the year 2013
if row[4]=='2013':
rate = int(row[11])
#print row
if rate == 0:
fill = "#F2F2F2"
elif rate < 500:
fill = "#FFF7EC"
elif rate < 1000:
fill = "#FEE8C8"
elif rate < 3500:
fill = "#FDD49E"
elif rate < 10000:
fill = "#FDBB84"
elif rate < 20000:
fill = "#FC8D59"
elif rate < 40000:
fill = "#EF6548"
elif rate < 80000:
fill = "#D7301F"
elif rate < 110000:
fill = "#B30000"
else:
fill = "#7F0000"
#country names need to be lowercase
print '.'+ row[2].lower() +' { fill: ' + fill+ ' }'
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment