def test_find_all(self):
		"""
		tests for find_all method in restcountry module
		"""
		all_countries = rc.find_all()
		for a_country in all_countries:
			self.assertTrue(hasattr(a_country, "callingCodes"), "Country object has attribute callingCodes")
			self.assertTrue(hasattr(a_country, "alpha2Code"), "Country object has attribute alpha2Code")
Beispiel #2
0
def get_countries_df():
    ## get list of dicionaries
    all_countries = rc.find_all()
    country_list = c_search()
    # convert it to dataframe
    country_df=pd.DataFrame(country_list)
    ## drop two irrelevant countries with string encoding issues
    country_df=country_df.drop(index=[79,146])
    
    return country_df
Beispiel #3
0
def c_search():
    all_countries = []
    for country in rc.find_all():
        country_dict = {}
        country_dict["country_iso"] = country.alpha3Code
        country_dict["country_name"] = country.country_name
        country_dict["population"] = country.population
        country_dict["n_languages"] = len(country.languages)
        country_dict["eng_language"] = sum([i=='en' for i in country.languages])
        country_dict["area"] = country.area
        country_dict["capital"] = country.capital
        country_dict["subregion"] = country.subregion
        country_dict["region"] = country.region
        all_countries.append(country_dict)
    return (all_countries)