def main(): Countries = pd.read_csv('countries.csv') income = pd.read_excel('indicator gapminder gdp_per_capita_ppp.xlsx', index_col='gdp pc test').T print Countries.head() #show the head of this data set when it is loaded print income.head() try: while True: print 'Enter quit or q to exit the program.' year = raw_input('Input the year you want to explore:(input next or n to skip this step!)\n') if str.lower(year) == 'quit' or str.lower(year) == 'q': #enter quit or q to exit the program sys.exit() elif str.lower(year) == 'next' or str.lower(year) == 'n': #enter next or n to skip this step break try: load_csv.display_distribution(year, income) except invalid_input: print 'invalid input!' except invalid_year: print 'year out of range[1800, 2012]' is_continue = raw_input('Do you want to enter another year? Enter ''finish'' to stop, otherwise continue:\n') if str.lower(is_continue) == 'finish': break elif str.lower(is_continue) == 'quit' or str.lower(is_continue) == 'q': sys.exit() # generate the defaulted plots print 'Now histograms and boxplots of year 2007-2012 will be generated and saved individually and we will exit the program, bye!' for year in range(2007, 2013): data_analysis = data_visulization(year, load_csv.merge_by_year(income, Countries, year)) data_analysis.data_histograms() data_analysis.data_boxplots() except KeyboardInterrupt: print 'Terminate abnormally'
def test_display_distribution_invalid_year(self): '''test display_distribution function raise error when input year out of range[2007-2012].''' Countries = pd.read_csv('countries.csv') self.assertRaises(invalid_year, lambda: load_csv.display_distribution(2013, Countries))
def test_display_distribution_invalid_input(self): '''test display_distribution function raise error when input year can not be converted to an integer.''' Countries = pd.read_csv('countries.csv') self.assertRaises(invalid_input, lambda: load_csv.display_distribution('tt', Countries))