Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2.  
  3. filehandle = open("population.csv")
  4. #print filehandle
  5. #<open file 'population.csv', mode 'r' at 0x1002d6c90>
  6.    
  7.  
  8. def print_population_list(filename):
  9.     linenumber = 0
  10.     global inwonerlijst
  11.     inwonerlijst = []
  12.     global yearlijst
  13.     yearlijst = []
  14.    
  15.     for line in filehandle:
  16.        linenumber+= 1
  17.        
  18.        if linenumber > 1:
  19.         year = line.split('"')[5]
  20.         year = int(year)
  21.         pop = line.split('"')[7]
  22.         pop = float(pop)
  23.         pop=pop*1000
  24.         pop=int(pop)
  25.         yearlijst.append(year)
  26.         inwonerlijst.append(pop)
  27.    
  28.     for i in range(len(inwonerlijst)):
  29.         print yearlijst[i],':', inwonerlijst[i]
  30.    
  31.    
  32. def print_population_dict(filename):
  33.     global popdic
  34.     popdic = dict(zip(yearlijst,inwonerlijst))
  35.     print popdic
  36.     return popdic
  37.    
  38. def plot_dic(title):
  39.     yearlist = popdic.keys()
  40.     poplist = popdic.values()
  41.    
  42.     plt.plot(yearlist,poplist)
  43.     plt.title(title)
  44.     plt.show()
  45.    
  46.          
  47.    
  48.        
  49. print_population_list('N:\population.csv')
  50. print_population_dict(filehandle)  
  51. plot_dic("pyplot")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement