Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- filehandle = open("population.csv")
- #print filehandle
- #<open file 'population.csv', mode 'r' at 0x1002d6c90>
- def print_population_list(filename):
- linenumber = 0
- global inwonerlijst
- inwonerlijst = []
- global yearlijst
- yearlijst = []
- for line in filehandle:
- linenumber+= 1
- if linenumber > 1:
- year = line.split('"')[5]
- year = int(year)
- pop = line.split('"')[7]
- pop = float(pop)
- pop=pop*1000
- pop=int(pop)
- yearlijst.append(year)
- inwonerlijst.append(pop)
- for i in range(len(inwonerlijst)):
- print yearlijst[i],':', inwonerlijst[i]
- def print_population_dict(filename):
- global popdic
- popdic = dict(zip(yearlijst,inwonerlijst))
- print popdic
- return popdic
- def plot_dic(title):
- yearlist = popdic.keys()
- poplist = popdic.values()
- plt.plot(yearlist,poplist)
- plt.title(title)
- plt.show()
- print_population_list('N:\population.csv')
- print_population_dict(filehandle)
- plot_dic("pyplot")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement