Created
August 23, 2016 22:28
-
-
Save zephyrzilla/57e1cfacea632044d29d6010539ca433 to your computer and use it in GitHub Desktop.
Python code to visualize ranking of countries based on their performance in Rio Olympics 2016 and their corresponding GDP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from matplotlib import pyplot as plt | |
| import operator | |
| # Country wise ranking at Rio Olympics 2016, Brazil | |
| # Data scraped off Google: search term "rio olympics 2016" | |
| # Preprocessed and converted to a Python dictionary | |
| rank_olympics_dict = {'Canada': 20, 'Lithuania': 64, 'Ethiopia': 44, 'Argentina': 27, \ | |
| 'Bahrain': 48, 'Slovenia': 45, 'Germany': 5, 'Spain': 14, 'Netherlands': 11, 'Jamaica': 16, 'United_States': 1, \ | |
| 'Cote_dIvoire': 51, 'Australia': 10, 'India': 67, 'Azerbaijan': 39, 'Kenya': 15, 'Tajikistan': 54, \ | |
| 'Turkey': 41, 'Mongolia': 67, 'France': 7, 'Norway': 74, 'Czech_Republic': 43, 'Singapore': 54, \ | |
| 'South_Africa': 30, 'China': 3, 'Armenia': 42, 'Ukraine': 31, 'Finland': 78, 'Indonesia': 46, 'Sweden': 29, \ | |
| 'Belarus': 40, 'Russia': 4, 'Bulgaria': 65, 'Romania': 47, 'Portugal': 78, 'Puerto_Rico': 54, 'Malaysia': 60, \ | |
| 'Austria': 78, 'Vietnam': 48, 'Hungary': 12, 'Niger': 69, 'Brazil': 13, 'Dominican_Republic': 78, \ | |
| 'Ireland': 62, 'Nigeria': 78, 'United_Arab_Emirates': 78, 'Iran': 25, 'Algeria': 62, 'Belgium': 35, 'Thailand': 35, \ | |
| 'Georgia': 38, 'Denmark': 28, 'Poland': 33, 'Moldova': 78, 'Morocco': 78, 'Croatia': 17, 'Switzerland': 24, \ | |
| 'Grenada': 69, 'Estonia': 78, 'Kosovo': 54, 'Uzbekistan': 21, 'Tunisia': 75, 'Colombia': 23, 'Burundi': 69, \ | |
| 'Fiji': 54, 'Qatar': 69, 'Italy': 9, 'New_Zealand': 19, 'Venezuela': 65, 'South_Korea': 8, 'Israel': 77, \ | |
| 'Jordan': 54, 'Kazakhstan': 22, 'Philippines': 69, 'Japan': 6, \ | |
| 'Trinidad_and_Tobago': 78, 'Mexico': 61, 'Egypt': 75, 'Great_Britain': 2, 'Serbia': 32, 'Greece': 26} | |
| # Country wise GDP (Gross Domestic Product) ranking | |
| # Data obtained from World Bank (http://data.worldbank.org/data-catalog/GDP-ranking-table) | |
| # Preprocessed and converted to a Python dictionary | |
| rank_gdp_dict = {'Brazil': 9, 'Canada': 10, 'Qatar': 46, 'Fiji': 79, 'Italy': 8, \ | |
| 'Dominican_Republic': 54, 'Kenya': 56, 'Serbia': 65, 'New_Zealand': 47, 'Lithuania': 63, \ | |
| 'Mongolia': 73, 'France': 6, 'Cote_dIvoire': 67, 'Ethiopia': 55, 'Georgia': 72, 'Trinidad_and_Tobago': 68, \ | |
| 'Ireland': 37, 'Grenada': 81, 'Nigeria': 20, 'Norway': 28, 'Argentina': 24, 'South_Korea': 11, 'Bahrain': 69, \ | |
| 'Uzbekistan': 57, 'Israel': 33, 'Australia': 13, 'Iran': 26, 'Algeria': 48, 'Singapore': 35, 'South_Africa': 36, \ | |
| 'Venezuela': 43, 'Jordan': 64, 'Austria': 27, 'Slovenia': 62, 'Czech_Republic': 44, 'China': 2, 'Armenia': 74, \ | |
| 'Belgium': 23, 'Germany': 4, 'Philippines': 31, 'Poland': 22, 'Spain': 12, 'Ukraine': 53, 'Hungary': 49, \ | |
| 'Netherlands': 17, 'Denmark': 34, 'Turkey': 18, 'Indonesia': 16, 'Moldova': 78, 'Morocco': 51, 'Sweden': 21, \ | |
| 'United_Arab_Emirates': 30, 'Croatia': 58, 'Finland': 39, 'Thailand': 25, 'Switzerland': 19, 'Belarus': 60, \ | |
| 'Russia': 14, 'Bulgaria': 59, 'Jamaica': 71, 'Romania': 45, 'Estonia': 70, 'Portugal': 40, 'Mexico': 15, \ | |
| 'Egypt': 29, 'Kazakhstan': 50, 'Great_Britain': 5, 'Kosovo': 76, 'India': 7, 'Azerbaijan': 66, 'Puerto_Rico': 52, \ | |
| 'Malaysia': 32, 'United_States': 1, 'Vietnam': 41, 'Tunisia': 61, 'Colombia': 38, 'Greece': 42, 'Burundi': 80, \ | |
| 'Japan': 3, 'Niger': 75, 'Tajikistan': 77} | |
| sorted_rank_olympics_dict = sorted(rank_olympics_dict.items(), key = operator.itemgetter(1)) | |
| olympics_country = [_[0] for _ in sorted_rank_olympics_dict] | |
| olympics_rank = [rank_olympics_dict[_] for _ in olympics_country] | |
| gdp_rank = [rank_gdp_dict[_] for _ in olympics_country] | |
| plt.title("Combined Statistics", fontweight = 'bold', fontsize = 18) | |
| plt.ylabel("Ranking", fontweight='bold') | |
| plt.xticks(range(len(olympics_country)), olympics_country, size = 'small', rotation = 'vertical') | |
| plt.plot(range(len(olympics_country)), olympics_rank, label = "Olympics rank") | |
| plt.plot(range(len(olympics_country)), gdp_rank, label = "GDP rank") | |
| plt.legend(loc = 'upper left') | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment