Example #1
0
    def boxplot(self, year, path=None):
        '''
        This function creates a boxplot of income by region for the given year. The plot will be saved to path if specified, otherwise, it will be shown
        '''
        mergedData = merge_by_year(year).dropna()
        plot = mergedData.boxplot(by="Region", rot=25).get_figure()

        if path == None:
            plot.show()
        else:
            plot.savefig(path)
 def histogram(self, year, path=None):
     '''
     This function creates a boxplot of income by region for the given year. The plot will be saved to path if specified, otherwise, it will be shown
     '''
     mergedData=merge_by_year(year).dropna()
     mergedData.hist("Income", by="Region", bins=20, xrot=25, xlabelsize=8, figsize=(8,8))
     
     if path==None:
         plt.show()
     else:
         plt.savefig(path)
 def boxplot(self, year, path=None):
     '''
     This function creates a boxplot of income by region for the given year. The plot will be saved to path if specified, otherwise, it will be shown
     '''
     mergedData=merge_by_year(year).dropna()
     plot=mergedData.boxplot(by="Region", rot=25).get_figure()
     
     if path==None:
         plot.show()
     else:
         plot.savefig(path)
Example #4
0
    def histogram(self, year, path=None):
        '''
        This function creates a boxplot of income by region for the given year. The plot will be saved to path if specified, otherwise, it will be shown
        '''
        mergedData = merge_by_year(year).dropna()
        mergedData.hist("Income",
                        by="Region",
                        bins=20,
                        xrot=25,
                        xlabelsize=8,
                        figsize=(8, 8))

        if path == None:
            plt.show()
        else:
            plt.savefig(path)
Example #5
0
 def test_merge_region(self):
     self.assertEqual(merge_by_year(1901)[merge_by_year(1901)["Country"]=="United States"]["Region"].item(), countries[countries["Country"]=="United States"]["Region"].item())
     self.assertEqual(merge_by_year(2001)[merge_by_year(2001)["Country"]=="United States"]["Region"].item(), merge_by_year(1901)[merge_by_year(1901)["Country"]=="United States"]["Region"].item())
     self.assertEqual(merge_by_year(1852)[merge_by_year(1852)["Country"]=="Australia"]["Region"].item(), countries[countries["Country"]=="Australia"]["Region"].item())
     self.assertEqual(merge_by_year(1985)[merge_by_year(1985)["Country"]=="China"]["Region"].item(), countries[countries["Country"]=="China"]["Region"].item())        
Example #6
0
 def test_merge_income(self):
     self.assertEqual(merge_by_year(1901)[merge_by_year(1901)["Country"]=="United States"]["Income"].item(), income_transpose["United States"].loc[1901])
     self.assertEqual(merge_by_year(2001)[merge_by_year(2001)["Country"]=="United States"]["Income"].item(), income_transpose["United States"].loc[2001])
     self.assertEqual(merge_by_year(1852)[merge_by_year(1852)["Country"]=="Australia"]["Income"].item(), income_transpose["Australia"].loc[1852])
     self.assertEqual(merge_by_year(1985)[merge_by_year(1985)["Country"]=="China"]["Income"].item(), income_transpose["China"].loc[1985])
Example #7
0
 def test_merge_columns(self):
     
     self.assertListEqual(list(merge_by_year(1801).columns.values),['Country', 'Income', 'Region'])