Example #1
0
 def test_country_name_3(self):
     """ Check whether country name was correctly renamed pre-merge"""
     data = pd.DataFrame(['Russian Federation', 'Macedonia', 'Burkina'],
                         columns=['Country'])
     self.assertEqual(list(data.Country[data.Country == 'Burkina'].values),
                      ['Burkina'])
     self.assertEqual(
         list(
             change.change_name(data).Country[
                 data.Country == 'Burkina'].values), ['Burkina Faso'])
Example #2
0
def merge_by_year(year):
    """Merges 'countries' with 'income' using 'Country' as key """
    """This is an inner join because we cannot use un-matched countries in plots """

    income_data = pd.DataFrame(income[year])
    income_data = income_data.rename(columns = {year:'Income'})
    
    # ! Important! 
    # I notice that sometimes country names differ in the two datatest and hence change 14 names in 'countries' data to ensure a match. See change_country_name.py for more information. Inner join n goes up from 177 to 191.
    countries_renamed = change.change_name(countries)
    
    # Country is a column in 'countries_renamed' but index in income_data
    merged_data =pd.merge(countries_renamed, income_data, left_on = 'Country',right_index=True)
    return merged_data
Example #3
0
def merge_by_year(year):
    """Merges 'countries' with 'income' using 'Country' as key """
    """This is an inner join because we cannot use un-matched countries in plots """

    income_data = pd.DataFrame(income[year])
    income_data = income_data.rename(columns={year: 'Income'})

    # ! Important!
    # I notice that sometimes country names differ in the two datatest and hence change 14 names in 'countries' data to ensure a match. See change_country_name.py for more information. Inner join n goes up from 177 to 191.
    countries_renamed = change.change_name(countries)

    # Country is a column in 'countries_renamed' but index in income_data
    merged_data = pd.merge(countries_renamed,
                           income_data,
                           left_on='Country',
                           right_index=True)
    return merged_data
Example #4
0
 def test_country_name_3(self):
     """ Check whether country name was correctly renamed pre-merge"""
     data = pd.DataFrame(['Russian Federation', 'Macedonia', 'Burkina'], columns=['Country'])
     self.assertEqual(list(data.Country[data.Country=='Burkina'].values),['Burkina'])
     self.assertEqual(list(change.change_name(data).Country[data.Country=='Burkina'].values),['Burkina Faso'])