Created
June 29, 2017 09:44
-
-
Save saliksyed/4df2fe6d228a094baca7b292ea8f57bb to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python2 | |
# -*- coding: utf-8 -*- | |
""" | |
Created on Thu Jun 29 11:26:56 2017 | |
@author: saliksyed | |
""" | |
gdp_data = open("gdp.dat").readlines() | |
gdp_by_country = {} | |
for line in gdp_data: | |
data = line.rstrip().split(",") | |
country = data[0] | |
country_code = data[1] | |
gdp_values = [] | |
for value in data[5:]: | |
# Remove the extra quotes in the data files | |
without_quotes = value[1:-1] | |
# We need to do this because there is some missing data which is represented by "" | |
if without_quotes == "": | |
final_parsed_value = None | |
else: | |
final_parsed_value = float(without_quotes) | |
gdp_values.append(final_parsed_value) | |
country_data = {} | |
country_data["country"] = country | |
country_data["country_code"] = country_code | |
country_data["gdp_values"] = gdp_values | |
gdp_by_country[country] = country_data | |
print gdp_by_country |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment