.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
def generate_population_dictionary_from_csv(filename):
"""Generate population dictionary from csv data file.
Returns a dictionary with this following format:
{
"Africa": { population: {100, 200, 300}, years: {2000, 2005, 2010}
"Asia": { population: {100, 200, 300}, years: {2000, 2005, 2010}
} """
output = {}
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': [], 'year': []}
output[continent]['population'].append(population)
output[continent]['year'].append(year)
return output
def generate_population_plots_from_dictionay(population_dictionary):
"""Generate the population plots from the population dictionary.
One plot per continent"""
for continent in population_dictionary:
year = population_dictionary[continent]['year']
population = population_dictionary[continent]['population']
plt.plot(year, population, label=continent, marker="o", alpha=0.5)
plt.title("Growth of Internet Users Per Continent")
plt.xlabel("Year")
plt.ylabel("Internet Users")
plt.grid(True)
plt.legend()
plt.show()
filename = 'data.csv'
"""Displays internet population in a plot"""
population_per_continent = generate_population_dictionary_from_csv(filename)
generate_population_plots_from_dictionay(population_per_continent)