.config
.gitignore
data.csv
generated-icon.png
main.py
Packager files
.pythonlibs
poetry.lock
pyproject.toml
Config files
.replit
replit.nix
import csv
import matplotlib.pyplot as plt
# Generate polutation diction from csv data
def generate_population_dictionary_from_csv(filename):
# Initialise the dictionary with nothing in it
output = {}
# Open the file and load the data, read csv file
with open(filename, 'r') as csvfile:
reader = csv.DictReader(csvfile)
for line in reader:
continent = line['continent']
year = int(line['year'])
population = int(line['population'])
if continent not in output:
output[continent] = {'population': [], 'years': []}
# Population and year values for the continents
output[continent]['population'].append(population)
output[continent]['years'].append(year)
return output
# Generate the population plots for each continent
def generate_population_plots_from_dictionary(population_dictonary):
for continent in population_dictonary:
years = population_dictonary[continent]['years']
population = population_dictonary[continent]['population']
plt.plot(years, population, label=continent, marker="o", alpha=0.5)
plt.title("Internet Population per continent")
plt.xlabel("Year")
plt.ylabel("Internet users (in billion users)")
plt.grid(True)
plt.tight_layout()
plt.legend()
plt.show()
filename = 'data.csv'
# Display internet population in a plot
population_per_continent = generate_population_dictionary_from_csv(filename)
generate_population_plots_from_dictionary(population_per_continent)